package cn.fl.capital.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.upload.constant.UploadConstant;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.*;
import cn.cmm.cache.framework.utils.PropertiesCacheUtils;
import cn.fl.capital.condition.*;
import cn.fl.capital.constant.CapitalConstant;
import cn.fl.capital.service.*;
import cn.fl.capital.utils.ExportFundList;
import cn.fl.capital.utils.ImportFundList;
import cn.fl.capital.vo.*;
import cn.fl.commons.result.ResponseData;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.export.condition.CapFundExportCondition;
import cn.fl.export.condition.CapFundVfLogExportCondition;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.insurance.constant.InsuranceConstant;
import cn.fl.insurance.vo.InsCapFundVO;
import cn.fl.insurance.vo.InsPlcBscInfoVO;
import cn.fl.mcr.api.IMcrBillMApiService;
import cn.fl.mcr.condition.McrBillMQC;
import cn.fl.mcr.dto.McrBillMDTO;
import cn.fl.preloan.IInsPlcBscInfoService;
import cn.fl.preloan.dto.insurance.GetInsPlcBscInfoRequest;
import cn.fl.preloan.dto.insurance.InsPlcBscInfoDTO;
import cn.fl.project.condition.PrjPrdDtlQueryCondition;
import cn.fl.project.condition.PrjPrdPaySchDQueryCondition;
import cn.fl.project.constant.PrjPrdPaySchMConstant;
import cn.fl.project.constant.PrjQuatPrpsConstant;
import cn.fl.project.constant.PrjQuatPrpsFeeConstant;
import cn.fl.project.service.*;
import cn.fl.project.vo.*;
import cn.fl.repay.service.IInsOfflineRepayLogService;
import cn.fl.repay.vo.InsOfflineRepayLogVO;
import cn.fl.system.constant.SysLogConstant;
import cn.lb.framework.poi.excel.ExcelImportUtil;
import cn.lb.framework.poi.excel.entity.ImportParams;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import fl.customer.facade.customer.api.ICustomerQueryApiService;
import fl.customer.facade.customer.condition.CstBscInfoQueryCondition;
import fl.customer.facade.customer.dto.CstBscInfoDTO;
import ins.car.facade.car.car.api.IInsQueryApiService;
import ins.car.facade.car.car.condition.InsPayInfoQC;
import ins.car.facade.car.car.dto.InsPayInfoDTO;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
/**
 * @Description: 客户资金表 控制层
 */
@Controller
@RequestMapping("/capital/capFund")
public class CapFundController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(CapFundController.class);

    /**
     * CapFund 服务层BEAN
     */
    @Autowired
    private ICapFundService capFundService;
    @Autowired
    private ICapFundVfLogService capFundVfLogService;
    @Autowired
    private ICapFundVfDtlService capFundVfDtlService;
    @Autowired
    private ICapPayInfoService capPayInfoService;
	@Autowired
	private ICapFundVfLogRService capFundVfLogRService;
	@Autowired
	private ICapFundOutLogService ICapFundOutLogService;


    /**
     * 客户 服务层BEAN
     */
    @Autowired
    private ICstBscInfoService cstBscInfoService;
    @Autowired
    private IPrjPrdPaySchDService prjPrdPaySchDService;
    @Autowired
    private IPrjPrdPaySchMService prjPrdPaySchMService;
    @Autowired
    private IPrjBscInfoService prjBscInfoService;
    @Autowired
    private IInsPlcBscInfoService insPlcBscInfoService;
    @Autowired
    private IPrjPrdDtlService prjPrdDtlService;
    @Autowired
    private ICapOverdueInfoService capOverdueInfoService;
    @Autowired
    private ICapFeeOutLogService capFeeOutLogService;

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService ;

    @Autowired
    private IPrjPrdPaySchMApiService prjPrdPaySchMApiService ;
    @Autowired
    private IInsQueryApiService insQueryApiService;

    
    @Autowired
    private ICapCstPayListApiService capCstPayListService;
    
    @Autowired
    private ICustomerQueryApiService customerQueryApiService;
    @Autowired
    private ICapFundIntoLogService capFundIntoLogService;
    @Autowired
    private IProfitAndLossService profitAndLossService;
    @Autowired
    private IInsOfflineRepayLogService insOfflineRepayLogService;
    @Autowired
    private IMcrBillMApiService mcrBillMApiService;

    /********************
     * 到来款列表页面
     ********************/
    @RequestMapping(value = "/toListPage.do", method = {RequestMethod.GET})
    public ModelAndView toListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载CapFund列表页面").setKeys("toListPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundList");
        return mav;
    }

    /*******************
     * 到新增来款页面
     *******************/
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载CapFund Add页面").setKeys("toAddPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundModify");
        this.prepare(request, mav);
        return mav;
    }

    /*****************
     * 到修改来款页面
     *****************/
    @RequestMapping(value = "/toModifyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toModifyPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载CapFund Modify页面").setKeys("toModifyPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundModify");
        this.prepare(request, mav);

        String id = request.getParameter("id");
        CapFundVO capFundVO = this.capFundService.selectById(Long.valueOf(id));
        if (capFundVO != null && capFundVO.getAcceptDate() != null) {
            capFundVO.setAcceptDates(DateUtils.formatDateToString(capFundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
        }
        if (capFundVO != null && capFundVO.getAcceptActualDate() != null) {
            capFundVO.setAcceptActualDates(DateUtils.formatDateToString(capFundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }
        mav.addObject("capFundVO", capFundVO);
        return mav;
    }

    /*****************
     * 到资金详情页面
     *****************/
    @RequestMapping(value = "/toFundDtlPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toFundDtlPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到资金详情页面").setKeys("toFundDtlPage",this.getRequestParameter(request),CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundDtl");
        this.prepare(request, mav);

        String id = request.getParameter("id");
        CapFundVO capFundVO = this.capFundService.selectById(Long.valueOf(id));
        if (capFundVO != null && capFundVO.getAcceptDate() != null) {
            capFundVO.setAcceptDates(DateUtils.formatDateToString(capFundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
        }
        if (capFundVO != null && capFundVO.getAcceptActualDate() != null) {
            capFundVO.setAcceptActualDates(DateUtils.formatDateToString(capFundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }
        mav.addObject("capFundVO", capFundVO);
        return mav;
    }

    /**
     * 加载数据字典数据、传值等
     *
     * @param request
     * @param mav
     */
    public void prepare(HttpServletRequest request, ModelAndView mav) {
        // 事业部
        List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
        mav.addObject("fundBelongOrgCdList", JSON.toJSONString(orgList));
    }

    /********************
     * 初始化列表
     ********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initCapFundList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String fundPid = request.getParameter("fundPid");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        
        CapFundQueryCondition qc = new CapFundQueryCondition();
        if(StringUtils.isEmpty(fundPid)) {
            qc.setFundPid(0l); //只查父资金
        }
        //设置查询条件？
        String type = request.getParameter("type");
        if (StringUtils.isNotEmpty(type)) {
            if ("1".equals(type)) {//待分解资金列表
                List<String> fundStatusList = new ArrayList<>();
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//0.未分解
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_1);//1.分解中
                qc.setFundStatusCdList(fundStatusList);//资金状态集合 CAP0004：0.未分解1.分解中2.已分解3.已作废
                //qc.setSortName("acceptActualDate");//按照到账日期排序
                qc.setSortName("crtTm");//按照创建日期排序
                qc.setSortOrder("desc");
            } else if ("2".equals(type)) {//已分解资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_2);//2.已分解
                qc.setSortName("mdfTm");//按照修改日期排序
                qc.setSortOrder("desc");
                qc.setResolveState("1");
            } else if("3".endsWith(type)){ // 冻结资金列表
            	   List<String> fundStatusList = new ArrayList<>();
                   fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_9); //9.已冻结
                   fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_6);//6.已转出
                   qc.setFundStatusCdList(fundStatusList);
                   qc.setSortName("mdfTm");//按照修改日期排序
                   qc.setSortOrder("desc");
            }else {//作废资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_3);//3.已作废
            }
        }else{
            qc.setSortName("crtTm");//默认按照创建日期排序
            qc.setSortOrder("desc");
        }

        String id = request.getParameter("id");
        String code = request.getParameter("code");
        String acceptCode = request.getParameter("acceptCode");
        String acceptName = request.getParameter("acceptName");
        String comeCode = request.getParameter("comeCode");
        String comeName = request.getParameter("comeName");
        String amountMin = request.getParameter("amountMin");
        String amountMax = request.getParameter("amountMax");
        String crtTmMin = request.getParameter("crtTmMin");
        String crtTmMax = request.getParameter("crtTmMax");
        String acceptDateMin = request.getParameter("acceptDateMin");
        String acceptDateMax = request.getParameter("acceptDateMax");
        String acceptActualDateMin = request.getParameter("acceptActualDateMin");
        String acceptActualDateMax = request.getParameter("acceptActualDateMax");
        String fundStatusCD = request.getParameter("fundStatusCD");//资金状态
        String cstId = request.getParameter("cstId");
        String ascrCd = request.getParameter("ascrCd");//认款标示 0.未认款 1.已认款
        String cstNm = request.getParameter("cstNm");//承租人
        String fundInputCd = request.getParameter("fundInputCd");//资金录入方式
        String relationPayId = request.getParameter("relationPayId");//关联业务主键
        String identifyOperator = request.getParameter("identifyOperator");//认款人
        String identifyOperatorNm = request.getParameter("identifyOperatorNm");//认款人名称
        String amount = request.getParameter("amount");
        String comeNameAlias = request.getParameter("comeNameAlias");//来款户名
        String comeCodeAlias = request.getParameter("comeCodeAlias");//来款账号
        String capTypeCd = request.getParameter("capTypCd"); //资金类型
        String fundSourcesCd = request.getParameter("fundSourcesCd");
        String paySchNo = request.getParameter("paySchNo");
        String isAutoCharge = request.getParameter("isAutoCharge");//是否自动划扣(1.是 0.否)

        if (StringUtils.isNotEmpty(id)) {
            qc.setId(Long.valueOf(id));
        }
        if (StringUtils.isNotBlank(code)) {
            qc.setCode(code);
        }
        if (StringUtils.isNotEmpty(acceptCode)) {
            qc.setAcceptCode(acceptCode);
        }
        if (StringUtils.isNotEmpty(acceptName)) {
            qc.setAcceptName(acceptName);
        }
        if (StringUtils.isNotEmpty(comeCode)) {
            qc.setComeCode(comeCode);
        }
        if (StringUtils.isNotEmpty(comeName)) {
            qc.setComeName(comeName);
        }
        if (StringUtils.isNotEmpty(amountMin)) {
            qc.setAmountMin(DecimalUtils.convertYuanToFen(Double.valueOf(amountMin)));
        }
        if (StringUtils.isNotEmpty(amountMax)) {
            qc.setAmountMax(DecimalUtils.convertYuanToFen(Double.valueOf(amountMax)));
        }
        if (StringUtils.isNotEmpty(crtTmMin)) {
            qc.setCrtTmMin(crtTmMin);
        }
        if (StringUtils.isNotEmpty(crtTmMax)) {
            qc.setCrtTmMax(crtTmMax);
        }
        if (StringUtils.isNotEmpty(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotEmpty(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMin)) {
            qc.setAcceptActualDateMin(acceptActualDateMin);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMax)) {
            qc.setAcceptActualDateMax(acceptActualDateMax);
        }
        if (StringUtils.isNotBlank(fundStatusCD)) {
            qc.setFundStatusCd(fundStatusCD);
        }
        if (StringUtils.isNotEmpty(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotEmpty(ascrCd)) {
            qc.setAscrCd(Integer.valueOf(ascrCd));
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(fundInputCd)) {
            qc.setFundInputCd(fundInputCd);
        }
        if (StringUtils.isNotEmpty(relationPayId)) {
            qc.setRelationPayId(Long.parseLong(relationPayId));
        }
        if (StringUtils.isNotEmpty(type)) {
        	if (!"2".equals(type)) {
        		if (StringUtils.isNotBlank(identifyOperator)) {
        			qc.setIdentifyOperator(Long.parseLong(identifyOperator));
        		}
        	}
        }
        if (StringUtils.isNotBlank(amount)) {
            qc.setAmount(DecimalUtils.convertYuanToFen(Double.parseDouble(amount)));
        }
        if (StringUtils.isNotBlank(identifyOperatorNm)) {
            qc.setIdentifyOperatorNm(identifyOperatorNm);
        }
        if (StringUtils.isNotBlank(comeNameAlias)) {
            qc.setComeNameAlias(comeNameAlias.trim());
        }
        if (StringUtils.isNotBlank(comeCodeAlias)) {
            qc.setComeCodeAlias(comeCodeAlias);
        }
        if(StringUtils.isNotBlank(capTypeCd)){
            qc.setCapTypCd(capTypeCd);
        }
        if(StringUtils.isNotBlank(fundSourcesCd)){
            qc.setFundSourcesCd(fundSourcesCd);
        }
        if(StringUtils.isNotBlank(paySchNo)){
            qc.setPaySchNo(paySchNo);
        }
        if(StringUtils.isNotBlank(isAutoCharge)){
            qc.setIsAutoCharge(Integer.parseInt(isAutoCharge));
        }
        page.setCondition(qc);
        BaseLogUtils.newLogger("初始化CapFund列表页面数据.DATA:").setKeys("initCapFundList",JSONObject.toJSONString(page),CurrentThreadContext.getCurrentUserName()).info();
        Pager pager = null ;
        try{
            pager = this.capFundService.searchListPage(page);
            //加载分解时间
            if("2".equals(type)){
             this.toFundDecomposeTimeList((List<CapFundVO>) pager.getResultList());
            }
          //加载剩余可转金额
            if("3".equals(type)){
             this.toFundSurplusOutAmtList((List<CapFundVO>) pager.getResultList());
            }
        }catch (Exception e){
            BaseLogUtils.newLogger("初始化CapFund列表页面数据异常").setKeys("initCapFundList",CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
        }
        List<CapFundVO> list=null;
        if(pager!=null){
              list = (List<CapFundVO>) pager.getResultList();
        }
        
        /*if (CollectionUtils.isNotEmpty(list)) {
            List docketRemList = new ArrayList();
            for (CapFundVO capFundVo : list) {
                if (StringUtils.isNotBlank(capFundVo.getDocketRem())) {
                    String[] remarks = capFundVo.getDocketRem().split(";");
                    for (String str : remarks) {
                        docketRemList.add(str);
                    }
                }
                
                capFundVo.setDocketRemList(docketRemList);
                if(CollectionUtils.isNotEmpty(docketRemList)){
                    docketRemList.clear();
                }
            }
        }*/
        ListPageVO<CapFundVO> listPage = new ListPageVO<CapFundVO>(list, pager.getTotalCount());
       
        return listPage;
    }

    /********************
     * 初始化列表
     ********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initFundList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initFundList(HttpServletRequest request, HttpServletResponse response) {
        CapFundQueryCondition qc = new CapFundQueryCondition();
        //设置查询条件？
        String type = request.getParameter("type");
        if (StringUtils.isNotEmpty(type)) {
            if ("1".equals(type)) {//待分解资金列表
                List<String> fundStatusList = new ArrayList<>();
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//0.未分解
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_1);//1.分解中
                qc.setFundStatusCdList(fundStatusList);//资金状态集合 CAP0004：0.未分解1.分解中2.已分解3.已作废
                qc.setSortName("acceptActualDate");//按照到账日期排序
            } else if ("2".equals(type)) {//已分解资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_2);//2.已分解
                qc.setSortName("mdfTm");//按照到账日期排序
                qc.setSortOrder("desc");
            } else if("3".equals(type)){ //冻结页面
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_9);//9.已冻结
                qc.setSortName("mdfTm");//按照到账日期排序
                qc.setSortOrder("desc");
            }else{//作废资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_3);//3.已作废
            }
        }
        String capTypeCd = request.getParameter("capTypCd"); //资金类型
        String cstId = request.getParameter("cstId");
        String relationPayId = request.getParameter("relationPayId");//关联业务主键
        String id = request.getParameter("id");
        String code = request.getParameter("code");
        String acceptCode = request.getParameter("acceptCode");
        String acceptName = request.getParameter("acceptName");
        String comeCode = request.getParameter("comeCode");
        String comeName = request.getParameter("comeName");
        String amountMin = request.getParameter("amountMin");
        String amountMax = request.getParameter("amountMax");
        String crtTmMin = request.getParameter("crtTmMin");
        String crtTmMax = request.getParameter("crtTmMax");
        String acceptDateMin = request.getParameter("acceptDateMin");
        String acceptDateMax = request.getParameter("acceptDateMax");
        String acceptActualDateMin = request.getParameter("acceptActualDateMin");
        String acceptActualDateMax = request.getParameter("acceptActualDateMax");
        String fundStatusCD = request.getParameter("fundStatusCD");//资金状态

        String ascrCd = request.getParameter("ascrCd");//认款标示 0.未认款 1.已认款
        String cstNm = request.getParameter("cstNm");//承租人
        String fundInputCd = request.getParameter("fundInputCd");//资金录入方式

        String identifyOperator = request.getParameter("identifyOperator");//认款人
        String identifyOperatorNm = request.getParameter("identifyOperatorNm");//认款人名称
        String amount = request.getParameter("amount");
        String comeNameAlias = request.getParameter("comeNameAlias");//来款户名
        String comeCodeAlias = request.getParameter("comeCodeAlias");//来款账号
        String paySchId = request.getParameter("paySchId");//流程中业务主键id
        String procInstId = request.getParameter("procInstId");//流程实例id
        if (StringUtils.isNotBlank(procInstId)) {
        	qc.setProcInstId(procInstId);
        }
        if (StringUtils.isNotEmpty(paySchId)) {
        	qc.setPaySchId(Long.valueOf(paySchId));
        }
        if (StringUtils.isNotEmpty(id)) {
            qc.setId(Long.valueOf(id));
        }
        if (StringUtils.isNotBlank(code)) {
            qc.setCode(code);
        }
        if (StringUtils.isNotEmpty(acceptCode)) {
            qc.setAcceptCode(acceptCode);
        }
        if (StringUtils.isNotEmpty(acceptName)) {
            qc.setAcceptName(acceptName);
        }
        if (StringUtils.isNotEmpty(comeCode)) {
            qc.setComeCode(comeCode);
        }
        if (StringUtils.isNotEmpty(comeName)) {
            qc.setComeName(comeName);
        }
        if (StringUtils.isNotEmpty(amountMin)) {
            qc.setAmountMin(DecimalUtils.convertYuanToFen(Double.valueOf(amountMin)));
        }
        if (StringUtils.isNotEmpty(amountMax)) {
            qc.setAmountMax(DecimalUtils.convertYuanToFen(Double.valueOf(amountMax)));
        }
        if (StringUtils.isNotEmpty(crtTmMin)) {
            qc.setCrtTmMin(crtTmMin);
        }
        if (StringUtils.isNotEmpty(crtTmMax)) {
            qc.setCrtTmMax(crtTmMax);
        }
        if (StringUtils.isNotEmpty(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotEmpty(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMin)) {
            qc.setAcceptActualDateMin(acceptActualDateMin);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMax)) {
            qc.setAcceptActualDateMax(acceptActualDateMax);
        }
        if (StringUtils.isNotBlank(fundStatusCD)) {
            qc.setFundStatusCd(fundStatusCD);
        }
        if (StringUtils.isNotEmpty(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotEmpty(ascrCd)) {
            qc.setAscrCd(Integer.valueOf(ascrCd));
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm);
        }
        if (StringUtils.isNotBlank(fundInputCd)) {
            qc.setFundInputCd(fundInputCd);
        }
        if (StringUtils.isNotEmpty(relationPayId)) {
            qc.setRelationPayId(Long.parseLong(relationPayId));
        }
        if (StringUtils.isNotEmpty(identifyOperator)) {
            qc.setIdentifyOperator(Long.parseLong(identifyOperator));
        }
        if (StringUtils.isNotBlank(amount)) {
            qc.setAmount(DecimalUtils.convertYuanToFen(Double.parseDouble(amount)));
        }
        if (StringUtils.isNotBlank(identifyOperatorNm)) {
            qc.setIdentifyOperatorNm(identifyOperatorNm);
        }
        if (StringUtils.isNotBlank(comeNameAlias)) {
            qc.setComeNameAlias(comeNameAlias.trim());
        }
        if (StringUtils.isNotBlank(comeCodeAlias)) {
            qc.setComeCodeAlias(comeCodeAlias);
        }
        if(StringUtils.isNotBlank(capTypeCd)){
            qc.setCapTypCd(capTypeCd);
        }
        qc.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        BaseLogUtils.newLogger("初始化CapFund列表页面数据.qc:" + JSONObject.toJSONString(qc)).setKeys("initCapFundList",CurrentThreadContext.getCurrentUserName()).info();
        List<CapFundVO> list = this.capFundService.searchList(qc);
        if (CollectionUtils.isNotEmpty(list)) {
            List docketRemList = new ArrayList();
            for(CapFundVO capFundVo : list){
                if(StringUtils.isNotBlank(capFundVo.getDocketRem())){
                    String[] remarks = capFundVo.getDocketRem().split(";");
                    for(String str : remarks){
                        docketRemList.add(str);
                    }
                }
                capFundVo.setDocketRemList(docketRemList);
                if(CollectionUtils.isNotEmpty(docketRemList)){
                    docketRemList.clear();
                }
                if (capFundVo.getUseAmt() != null) {
                	capFundVo.setUseAmts(DecimalUtils.convertFenToYuan(capFundVo.getUseAmt()));
                } else {
                	capFundVo.setUseAmts(DecimalUtils.convertFenToYuan(capFundVo.getAvailableAmount()));
				}
            }
            return new ListPageVO<CapFundVO>(list,list.size());
        } else {
            return new ListPageVO<CapFundVO>(new ArrayList<CapFundVO>(0), 0);
        }
    }

    /*******************
     * 只删除关联id删除数据
     *******************/
    @RequestMapping(value = "/removeOnlyRelationPayIdByIds.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeOnlyRelationPayIdByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newLogger("删除CapFund数据,主键参数为空!").setKeys("removeCapFundByIds",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }

        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }
        try {
        	boolean success = this.capFundService.deleteOnlyRelationPayIdByIds(idsList);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.newLogger("删除CapFund数据失败,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeCapFundByIds",CurrentThreadContext.getCurrentUserName()).info();
            }
            BaseLogUtils.newLogger("删除CapFund数据成功,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeCapFundByIds",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("删除CapFund数据失败,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeCapFundByIds",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("删除CapFund数据失败,系统错误.ID:" + JSONObject.toJSONString(idsList)).setKeys("removeCapFundByIds",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }
    
    /*******************
     * 删除数据
     *******************/
    @RequestMapping(value = "/removeByIds.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO removeCapFundByIds(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String ids = request.getParameter("ids");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_DELETE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newLogger("删除CapFund数据,主键参数为空!").setKeys("removeByIds",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }

        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }

        try {
            boolean success = this.capFundService.removeByIds(idsList);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DELETE_FAIL);
                BaseLogUtils.newLogger("删除CapFund数据失败,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeByIds",CurrentThreadContext.getCurrentUserName()).info();
            }
            BaseLogUtils.newLogger("删除CapFund数据成功,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeByIds",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("删除CapFund数据失败,ID:" + JSONObject.toJSONString(idsList)).setKeys("removeByIds",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("删除CapFund数据失败,系统错误.ID:" + JSONObject.toJSONString(idsList)).setKeys("removeByIds",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /**********************
     * 得到一条记录
     * @param request
     * @return
     * @throws Exception
     ***********************/
    @RequestMapping(value = "/getById.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getCapFundById(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String id = request.getParameter("id");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newLogger("获取CapFund数据,主键参数为空.").setKeys("getCapFundById",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }

        try {
            CapFundVO vo = this.capFundService.selectById(Long.valueOf(id));
            if (null == vo) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_QUERY_DATA_IS_EMPTY);
                BaseLogUtils.newLogger("获取CapFund数据不存在,ID:" + id).setKeys("getCapFundById",CurrentThreadContext.getCurrentUserName()).info();
            }
            result.setData(vo);
            BaseLogUtils.newLogger("获取CapFund数据成功,ID:" + id).setKeys("getCapFundById",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取CapFund数据失败,ID:" + id).setKeys("getCapFundById",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("获取CapFund数据失败,系统错误.ID:" + id).setKeys("getCapFundById",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*********
     * 新增
     *********/
    @RequestMapping(value = "/add.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addCapFund(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        CapFundVO entity = null;//获取参数
        try {
            entity = this.getRequestParamForCapFund(request);//获取参数
            Long id = this.capFundService.add(entity);
            result.setData(id);
            BaseLogUtils.newLogger("新增CapFund数据成功,ID:" + id + ".DATA:" + JSONObject.toJSONString(entity)).setKeys("addCapFund",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("新增CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("addCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("新增CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("addCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*************
     * 修改
     *************/
    @RequestMapping(value = "/modify.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyCapFund(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        CapFundVO entity = null;
        try {
            entity = this.getRequestParamForCapFund(request);
            if (entity.getId() == null) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("修改CapFund信息,主键参数为空！").setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }

            boolean success = this.capFundService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            result.setData(entity.getId());
            BaseLogUtils.newLogger("修改CapFund数据成功.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*************
     * 修改
     *************/
    @RequestMapping(value = "/modifyRem.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object modifyRem(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        CapFundVO entity = new CapFundVO();
        try {
            String id = request.getParameter("id");
            String docketRem = request.getParameter("docketRem");
            String fundBelongOrgCd = request.getParameter("fundBelongOrgCd");
            if (StringUtils.isEmpty(id)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("修改CapFund信息,主键参数为空！").setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            entity.setId(Long.valueOf(id));
            entity.setDocketRem(docketRem);
            entity.setFundBelongOrgCd(fundBelongOrgCd);
            boolean success = this.capFundService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            result.setData(entity.getId());
            BaseLogUtils.newLogger("修改CapFund数据成功.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyCapFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*********************
     * 到资金导入列表面
     *********************/
    @RequestMapping(value = "/toFundImportPage.do", method = {RequestMethod.GET})
    public ModelAndView toFundImportPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载toFundImportPage资金导入列表面").setKeys("toFundImportPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundImportList");
        String filePath = request.getParameter("filePath");//文件路径
        mav.addObject("filePath", filePath);
        List<CapFundVO> list = ImportFundList.importXls(filePath);
        if (CollectionUtils.isNotEmpty(list)) {
            mav.addObject("fundList", JSON.toJSONString(list));
            mav.addObject("success", "true");//导入资金数据验证通过
            for (CapFundVO vo : list) {
                if ("1".equals(vo.getFundStatusCd())) {
                    mav.addObject("success", "false");//导入资金数据验证不通过
                    break;
                }
            }
        } else {
            mav.addObject("success", "false");//无导入资金数据
        }
        return mav;
    }

    /***********************
     * 资金批量导入
     ***********************/
    @RequestMapping(value = "/importFund.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO importFund(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "资金导入成功");
        String filePath = request.getParameter("filePath");//文件路径
        List<CapFundVO> list = ImportFundList.importXls(filePath);
        if (CollectionUtils.isNotEmpty(list)) {
            Date crtTm = new Date();
            for (CapFundVO vo : list) {
                /*if(!"0".equals(vo.getFundStatusCd())){//问题数据过滤掉
                    list.remove(vo);
                    continue;
                }*/
                vo.setAmount(DecimalUtils.convertYuanToFen(vo.getAmountDou()));
                vo.setAvailableAmount(vo.getAmount());
                vo.setUsedAmount(0L);
                vo.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_DECO_U);//未分解
                vo.setFundSourcesCd(CapitalConstant.CODE_CAP_FUND_SRC_C);//正常来款
                vo.setAcceptActualDate(vo.getAcceptDate());//实际到账日期=交易时间
                vo.setFundInputCd(CapitalConstant.CODE_CAP_FUND_INPUT_CD_2);//资金录入类型：手工批量上传
                vo.setCrtTm(crtTm);
                vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                vo.setDocketRem(vo.getDocketRem());
            }
            boolean flag = this.capFundService.add(list);
            if (!flag) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.newLogger("资金导入失败.DATA:" + filePath).setKeys("importFund",CurrentThreadContext.getCurrentUserName()).info();
            }
            BaseLogUtils.newLogger("资金导入成功.DATA:" + filePath).setKeys("importFund",CurrentThreadContext.getCurrentUserName()).info();
        } else {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.newLogger("资金导入失败.导入数据为空").setKeys("importFund",CurrentThreadContext.getCurrentUserName()).info();
        }
        return result;
    }

    /**********************
     * 来款手动核销 列表页面
     **********************/
    @RequestMapping(value = "/toManualListPage.do", method = {RequestMethod.GET})
    public ModelAndView toManualListPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mav = null;
        String type = request.getParameter("type");
        if (StringUtils.isNotEmpty(type)) {
        	  List<KeyValueVO> fundConfirmByListPage = this.toFundConfirmByListPage(request, response);
            if ("1".equals(type)) {//待分解资金列表
                BaseLogUtils.newLogger("加载到手动核销-待分解资金列表").setKeys("toManualListPage",CurrentThreadContext.getCurrentUserName()).info();
            } else if ("2".equals(type)) {//已分解资金列表
                BaseLogUtils.newLogger("加载到手动核销-已分解资金列表").setKeys("toManualListPage",CurrentThreadContext.getCurrentUserName()).info();
            } else {//作废资金列表
                BaseLogUtils.newLogger("加载到手动核销-作废资金列表").setKeys("toManualListPage",CurrentThreadContext.getCurrentUserName()).info();
            }

            mav = new ModelAndView("capital/capFund/capManualVerifyList");
            mav.addObject("fundConfirmByListPage", fundConfirmByListPage);
            mav.addObject("fundConfirmByListPageListJSON", JSONArray.fromObject(fundConfirmByListPage));
            mav.addObject("type", type);

        } else {
            BaseLogUtils.newLogger("加载到手动核销管理页面").setKeys("toManualListPage",CurrentThreadContext.getCurrentUserName()).info();
            mav = new ModelAndView("capital/capFund/capManualVerify");
        }
        return mav;
    }

    /*********************************
     * 来款手动核销 到认款页面
     *********************************/
    @RequestMapping(value = "/toFundConfirmPage.do", method = {RequestMethod.GET})
    public ModelAndView toCapFundConfirmPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到手动核销认款页面").setKeys("toFundConfirmPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundConfirm");
        String id = request.getParameter("id");//资金ID
        String cstNm = request.getParameter("cstNm");//来款账户名称
        String cstAcc = request.getParameter("cstAcc");//来款账号
        String vfFlag = request.getParameter("vfFlag");//是否需要自动核销 1.是 0.否
        String opTyp = request.getParameter("opTyp");//操作类型 1.财务认款 2.客户经理认款
        if(StringUtils.isNotBlank(opTyp)&&opTyp.equals("2")){
            mav.setViewName("capital/capFund/capConfirmByCstMgr");
        }
        mav.addObject("fundId", id);
        mav.addObject("cstNm", cstNm);
        mav.addObject("cstAcc", cstAcc);
        mav.addObject("vfFlag", vfFlag);
        return mav;
    }

    /*********************************
     * 到自主认款-待认款项页面
     *********************************/
    @RequestMapping(value = "/toFundConfirmListPage.do", method = {RequestMethod.GET})
    public ModelAndView toFundConfirmListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到认款管理-待认款项页面").setKeys("toFundConfirmListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundConfirmByList");
        List<KeyValueVO> fundConfirmByListPage = this.toFundConfirmByListPage(request, response);
        mav.addObject("fundConfirmByListPage", fundConfirmByListPage);
        mav.addObject("fundConfirmByListPageListJSON", JSONArray.fromObject(fundConfirmByListPage));
        String type = request.getParameter("type");
        mav.addObject("type", type);
        if ("2".equals(type)) {
            mav.addObject("operator", CurrentThreadContext.getCurrentUserId());
        }else if("3".equals(type)){
            mav.addObject("operator", CurrentThreadContext.getCurrentUserId());
        }
        return mav;
    }

    /*********************************
     * 加载到认款管理页面
     *********************************/
    @RequestMapping(value = "/toCapConfirmPage.do", method = {RequestMethod.GET})
    public ModelAndView toCapConfirmPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到认款管理页面").setKeys("toCapConfirmPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capConfirmFund");
        return mav;
    }

    /********************************
     * 来款手动核销 认款、重置认款
     ********************************/
    @RequestMapping(value = "/confirmFund.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object confirmFund(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        CapFundVO entity = null;
        try {
            String id = request.getParameter("id");//资金ID
            String ids = request.getParameter("ids");//资金ID集合
            if (StringUtils.isBlank(id) && StringUtils.isBlank(ids)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("认款修改CapFund信息,主键参数为空").setKeys("confirmFund",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            String cstId = request.getParameter("cstId");//客户ID
            String cstNm = request.getParameter("cstNm");//客户名称
            String isNeedVf = request.getParameter("vfFlag");//是否需要自动核销
            String docketRem = request.getParameter("docketRem");//认款备注
            String paySchIds = request.getParameter("paySchIdList");//支付表集合
            String relationPayId = request.getParameter("relationPayId");//关联ID

            entity = new CapFundVO();
            if (StringUtils.isNotEmpty(isNeedVf)) {
                entity.setIsNeedVf(Integer.parseInt(isNeedVf));
            }
            if (StringUtils.isNotBlank(docketRem)) {
                entity.setDocketRem(docketRem);
            }
            if(StringUtils.isNotBlank(paySchIds)){
                entity.setPaySchIds(paySchIds);
            }
            if(StringUtils.isNotEmpty(id)){
                entity.setId(Long.valueOf(id));//资金编号
            }
            if(StringUtils.isNotBlank(ids)){
                List<Long> idsList = new ArrayList<>();
                JSONArray idsArray = JSONArray.fromObject(ids);
                for (Object object : idsArray) {
                    idsList.add(Long.valueOf(object.toString()));
                }
                entity.setIdList(idsList);
            }
            if(StringUtils.isNotEmpty(relationPayId)){
                entity.setRelationPayId(Long.valueOf(relationPayId));
            }

            if (StringUtils.isBlank(cstId)) {
                BaseLogUtils.newLogger("重置认款id:" + id).setKeys("confirmFund",CurrentThreadContext.getCurrentUserName()).info();
                entity.setCstId(null);//承租人ID
                entity.setCstNm(null);//承租人名称
                entity.setIdentifyOperator(null);//认款人ID
                entity.setIdentifyOperatorNm(null);//认款人
                entity.setIdentifyTime(null);
            } else {
                BaseLogUtils.newLogger("认款[资金ID=" + id + ",客户ID=" + cstId + ",操作人ID=" + CurrentThreadContext.getCurrentUserId() + "]").setKeys("confirmFund",CurrentThreadContext.getCurrentUserName()).info();
                entity.setCstId(Long.valueOf(cstId));//承租人ID
                entity.setCstNm(cstNm);//承租人名称
                entity.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
                entity.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人
                entity.setIdentifyTime(new Date());
            }
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            //修改资金所属客户信息
            result = this.capFundService.modifyFundCstInfo(entity);
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("认款修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("confirmFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("认款修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("confirmFund",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*******************************
     * 手动核销 到资金分解页面
     *******************************/
    @RequestMapping(value = "/toDecomposePage.do", method = {RequestMethod.GET})
    public ModelAndView toDecomposePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载toDecomposePage到资金手动分解页面" ).setKeys("toDecomposePage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundDecompose");
        String id = request.getParameter("id");//资金ID
        CapFundVO vo = capFundService.selectById(Long.valueOf(id));//资金
        if (vo == null) {
            return mav;
        }
        if (vo.getAcceptDate() != null) {
            vo.setAcceptDates(DateUtils.formatDateToString(vo.getAcceptDate(), DateUtils.YYYY_MM_DD));
        }
        if (vo.getAcceptActualDate() != null) {
            vo.setAcceptActualDates(DateUtils.formatDateToString(vo.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }

        //判断资金是否分解过
        if (vo.getUsedAmount() > 0) {
            //查询资金分解人，可能有多个
            StringBuffer fundDecomUsrNm = new StringBuffer();
            CapFundVfLogQueryCondition vfLogQueryCondition = new CapFundVfLogQueryCondition();
            vfLogQueryCondition.setFundId(Long.valueOf(id));
            vfLogQueryCondition.setVfTypCd(CapitalConstant.CODE_VF_TYP_CD_1);
            List<CapFundVfLogVO> vfLogList = this.capFundVfLogService.searchList(vfLogQueryCondition);
            if (CollectionUtils.isNotEmpty(vfLogList)) {
                for (CapFundVfLogVO vfLogVO : vfLogList) {
                    fundDecomUsrNm.append(vfLogVO.getVfUsrNm() + " ");
                }
            }
            vo.setFundDecomUsrNm(fundDecomUsrNm.toString());
        }

        mav.addObject("capFundVO", vo);
        return mav;
    }

    /****************************
     * 资金分解 手工分解
     ****************************/
    @RequestMapping(value = "/decompose.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO fundDecompose(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("手动资金分解开始" ).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "资金分解成功");
        String fundId = request.getParameter("fundId");//资金ID
        String docketRem = request.getParameter("docketRem");//备注
        String entryTypCd = request.getParameter("entryTypCd");//入账类型
        String pays = request.getParameter("payList");//待分解支付表明细
        if (StringUtils.isBlank(fundId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON_0);
            BaseLogUtils.newLogger("资金手动分解失败.ERROR:未找到分解的资金信息" ).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }
        if (StringUtils.isBlank(pays)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON);
            BaseLogUtils.newLogger("资金手动分解失败.DATA:" + fundId + ".ERROR:未找到分解的支付表明细").setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }
        CapFundQueryCondition qc = new CapFundQueryCondition();
        qc.setId(Long.valueOf(fundId));//资金ID
        qc.setDocketRem(docketRem);//分解备注
        qc.setAdditionalCondition(pays);//待分解支付表明细
        qc.setEntryTypCd(entryTypCd);//入账类型

        result = this.capFundService.addFundManualDecompose(qc);
        BaseLogUtils.newLogger("手动资金分解结束" + JSON.toJSONString(result)).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
        return result;
    }



    /**********************
     * 来款手动核销 列表页面【未启用支付表】
     **********************/
    @RequestMapping(value = "/toManualListPageAbnormal.do", method = {RequestMethod.GET})
    public ModelAndView toManualListPageAbnormal(HttpServletRequest request, HttpServletResponse response) {
        String type = request.getParameter("type");
        ModelAndView mav = new ModelAndView("capital/capFund/capManualVerifyListAbnormal");
        if ("1".equals(type)) {//待分解资金列表
            List<KeyValueVO> fundConfirmByListPage = this.toFundConfirmByListPage(request, response);
            mav.addObject("fundConfirmByListPage", fundConfirmByListPage);
            mav.addObject("fundConfirmByListPageListJSON", JSONArray.fromObject(fundConfirmByListPage));
            mav.addObject("type", type);
            BaseLogUtils.newLogger("加载到手动核销【异常支付表】-待分解清单列表").setKeys("toManualListPageAbnormal",CurrentThreadContext.getCurrentUserName()).info();
        }else{
            BaseLogUtils.newLogger("加载到手动核销【异常支付表】-参数错误").setKeys("toManualListPageAbnormal",CurrentThreadContext.getCurrentUserName()).info();
        }
        return mav;
    }

    /*******************************
     * 手动核销 到资金分解页面【异常支付表核销】
     *******************************/
    @RequestMapping(value = "/toDecomposePageAbnormal.do", method = {RequestMethod.GET})
    public ModelAndView toDecomposePageAbnormal(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载toDecomposeAbnormalPage到资金手动分解页面" ).setKeys("toDecomposePage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundDecomposeAbnormal");
        String id = request.getParameter("id");//资金ID
        CapFundVO vo = capFundService.selectById(Long.valueOf(id));//资金
        if (vo == null) {
            return mav;
        }
        if (vo.getAcceptDate() != null) {
            vo.setAcceptDates(DateUtils.formatDateToString(vo.getAcceptDate(), DateUtils.YYYY_MM_DD));
        }
        if (vo.getAcceptActualDate() != null) {
            vo.setAcceptActualDates(DateUtils.formatDateToString(vo.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }

        //判断资金是否分解过
        if (vo.getUsedAmount() > 0) {
            //查询资金分解人，可能有多个
            StringBuffer fundDecomUsrNm = new StringBuffer();
            CapFundVfLogQueryCondition vfLogQueryCondition = new CapFundVfLogQueryCondition();
            vfLogQueryCondition.setFundId(Long.valueOf(id));
            vfLogQueryCondition.setVfTypCd(CapitalConstant.CODE_VF_TYP_CD_1);
            List<CapFundVfLogVO> vfLogList = this.capFundVfLogService.searchList(vfLogQueryCondition);
            if (CollectionUtils.isNotEmpty(vfLogList)) {
                for (CapFundVfLogVO vfLogVO : vfLogList) {
                    fundDecomUsrNm.append(vfLogVO.getVfUsrNm() + " ");
                }
            }
            vo.setFundDecomUsrNm(fundDecomUsrNm.toString());
        }

        mav.addObject("capFundVO", vo);
        return mav;
    }




    /**
     * 资金分解，查询待分解支付表明细+罚息  来款手动核销页面
     * 【异常支付表核销】
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/searchPaySchDListAbnormal.do", method = {RequestMethod.GET})
    @ResponseBody
    @Deprecated
    public Object searchPaySchDListAbnormal(HttpServletRequest request, HttpServletResponse response) {
        String cstId = request.getParameter("cstId");//客户ID
        String acceptActualDate = request.getParameter("acceptActualDate");//实际到账日期
        String payPd = request.getParameter("payPd");//期次，首期款核销
        String type = request.getParameter("type");//

        CapFundQueryCondition qc = new CapFundQueryCondition();
        if (StringUtils.isNotBlank(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotBlank(acceptActualDate)) {
            qc.setAcceptActualDate(DateUtils.formatStringToDate(acceptActualDate, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(payPd)) {
            qc.setPayPd(Long.valueOf(payPd));
        }
        if (StringUtils.isNotEmpty(type)) {
            qc.setType(type);
        }

        if (capFundService.isOpenAbnormalDecompose()) {
            //查询待分解支付表+罚息toAddFundPage.do
            List<PrjPrdPaySchDVO> voList = this.capFundService.searchPaySchDList(qc);
            if (CollectionUtils.isNotEmpty(voList)) {
                return new ListPageVO<PrjPrdPaySchDVO>(voList, voList.size());
            }
        }else{
            //查询未启用支付表的本金利息和罚息
            List<BillItemVO> billItemVOList = this.capFundService.queryNotEnabledBillItemList(qc);
            if (CollectionUtils.isNotEmpty(billItemVOList)) {
                return new ListPageVO<>(billItemVOList, billItemVOList.size());
            }
        }
        return null;
    }

    /****************************
     * 资金分解 手工分解【异常支付表核销】
     ****************************/
    @RequestMapping(value = "/decomposeAbnormal.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO fundDecomposeAbnormal(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        BaseLogUtils.newLogger("异常支付表-手动资金分解开始" ).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "资金分解成功");
        String fundId = request.getParameter("fundId");//资金ID
        String docketRem = request.getParameter("docketRem");//备注
        String entryTypCd = request.getParameter("entryTypCd");//入账类型
        String pays = request.getParameter("payList");//待分解支付表明细
        if (StringUtils.isBlank(fundId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON_0);
            BaseLogUtils.newLogger("异常支付表-资金手动分解失败.ERROR:未找到分解的资金信息" ).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }
        if (StringUtils.isBlank(pays)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON);
            BaseLogUtils.newLogger("异常支付表-资金手动分解失败.DATA:" + fundId + ".ERROR:未找到分解的支付表明细").setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }
        CapFundQueryCondition qc = new CapFundQueryCondition();
        qc.setId(Long.valueOf(fundId));//资金ID
        qc.setDocketRem(docketRem);//分解备注
        qc.setAdditionalCondition(pays);//待分解支付表明细
        qc.setEntryTypCd(entryTypCd);//入账类型

        result = this.capFundService.addFundManualDecomposeAbnormal(qc);
        BaseLogUtils.newLogger("异常支付表-手动资金分解结束" + JSON.toJSONString(result)).setKeys("fundDecompose",CurrentThreadContext.getCurrentUserName()).info();
        return result;
    }

    /*************************
     * 来款自动核销 到列表页面
     ************************/
    @RequestMapping(value = "/toAutoVerify.do", method = {RequestMethod.GET})
    public ModelAndView toAutoListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载toAutoVerify来款自动核销页面").setKeys("toAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capAutoVerify");
        return mav;
    }

    /**********************************
     * 来款自动核销 到批量认款列表页面
     **********************************/
    @RequestMapping(value = "/toConfirmListPage.do", method = {RequestMethod.GET})
    public ModelAndView toConfirmListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到来款自动核销批量认款列表页面").setKeys("toConfirmListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundConfirmList");
        return mav;
    }

    /**********************************
     * 来款自动核销-批量认款
     **********************************/
    @RequestMapping(value = "/batchConfirmFund.do", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public DataResultVO batchConfirmFund(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "认款完成");
        String ids = request.getParameter("ids");//资金ID集合
        List<Long> idsList = new ArrayList<Long>();
        if (StringUtils.isNotBlank(ids)) {
            JSONArray idsArray = JSONArray.fromObject(ids);
            for (Object object : idsArray) {
                idsList.add(Long.valueOf(object.toString()));
            }
        }
        CapFundQueryCondition qc = new CapFundQueryCondition();
        if (CollectionUtils.isNotEmpty(idsList)) {
            qc.setIdList(idsList);
        }
        //TODO 需不需要区分：资金录入方式 1.手工录入 2.批量导入
        //qc.setFundInputCd(CapitalConstant.CODE_CAP_FUND_INPUT_CD_3);
        qc.setAscrCd(CapitalConstant.CODE_CAP_FUND_CONFIRM_N);//认款标示 0.未认款 1.已认款
        qc.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());
        qc.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());
        qc.setOtherCondition("AND T.FUND_SOURCES_CD != 7 AND T.FUND_STATUS_CD IN (0, 1)");
        List<CapFundVO> list = this.capFundService.batchModifyFundCstInfo(qc);
        result.setData(JSON.toJSONString(list));
        return result;
    }

    /**********************************
     * 来款自动核销-批量认款结果
     **********************************/
    @RequestMapping(value = "/toConfirmResultPage.do", method = {RequestMethod.POST, RequestMethod.GET})
    public ModelAndView toConfirmResultPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mav = new ModelAndView("capital/capFund/capFundConfirmResult");
        return mav;
    }

    /******************************
     * 来款自动核销 到自动分解列表页面
     ******************************/
    @RequestMapping(value = "/toAutoVerifyListPage.do", method = {RequestMethod.GET})
    public ModelAndView toAutoVerifyListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到来款自动核销自动分解列表页面").setKeys("toAutoVerifyListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capAutoVerifyList");
        return mav;
    }

    /*******************************
     * 来款自动核销 批量分解
     *******************************/
    @RequestMapping(value = "/batchDecomFund.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO batchDecomFund(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("来款自动分解开始").setKeys("batchDecomFund",CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = null;
        String crtTmMin = request.getParameter("crtTmMin");//导入起始日期
        String crtTmMax = request.getParameter("crtTmMax");//导入结束日期
        String acceptDateMin = request.getParameter("acceptDateMin");//到账起始日期
        String acceptDateMax = request.getParameter("acceptDateMax");//到账结束日期
        String code = request.getParameter("code");//资金编号
        String acceptCode = request.getParameter("acceptCode");//收款账号
        String identifyOperatorNm = request.getParameter("identifyOperatorNm");//认款人名称
        String comeName = request.getParameter("comeName");
        //待分解资金ID集合
        String ids = request.getParameter("ids");

        //资金分解
        CapFundQueryCondition qc = new CapFundQueryCondition();
        if (StringUtils.isNotBlank(crtTmMin)) {
            qc.setCrtTmMin(crtTmMin);
        }
        if (StringUtils.isNotBlank(crtTmMax)) {
            qc.setCrtTmMax(crtTmMax);
        }
        if (StringUtils.isNotBlank(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotBlank(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotBlank(code)) {
            qc.setCode(code);
        }
        if (StringUtils.isNotBlank(acceptCode)) {
            qc.setAcceptCode(acceptCode);
        }
        if (StringUtils.isNotEmpty(comeName)) {
            qc.setComeName(comeName);
        }
        if (StringUtils.isNotBlank(identifyOperatorNm)) {
            qc.setIdentifyOperatorNm(identifyOperatorNm);
        }
        List<Long> idsList = null;
        if (StringUtils.isNotBlank(ids)) {
            String[] idArray = ids.split(",");
            idsList = new ArrayList<>(idArray.length);
            for (String id : idArray) {
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                idsList.add(Long.parseLong(id));
            }
        }
        if (CollectionUtils.isNotEmpty(idsList)) {
            qc.setIdList(idsList);
        }else{
            return new DataResultVO(BaseConstant.IS_YESNO_NO,"请选择自动分解的来款");
        }
        result = this.capFundService.batchDecomFund(qc);
        BaseLogUtils.newLogger("来款自动分解结束" + result.getInfo()).setKeys("batchDecomFund",CurrentThreadContext.getCurrentUserName()).info();
        return result;
    }


    /****************************
     * 导出资金分解支付表明细
     ****************************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportFundDecom.do", method = {RequestMethod.GET})
    public void exportFundDecom(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("导出资金分解支付表明细").setKeys("exportFundDecom",CurrentThreadContext.getCurrentUserName()).info();
        String fundId = request.getParameter("fundId");//资金ID
        String vfId = request.getParameter("vfId");//分解Id
        if (StringUtils.isEmpty(fundId) && StringUtils.isEmpty(vfId)) {
            BaseLogUtils.newLogger("导出资金分解支付表明细,资金ID和分解ID为空").setKeys("exportFundDecom",CurrentThreadContext.getCurrentUserName()).info();
            return;
        }

        CapFundVfDtlQueryCondition vfDtlQueryCondition = new CapFundVfDtlQueryCondition();
        if (StringUtils.isNotEmpty(fundId)) {//资金ID
            vfDtlQueryCondition.setFundId(Long.valueOf(fundId));
        }
        if (StringUtils.isNotEmpty(vfId)) {
            vfDtlQueryCondition.setVfId(Long.valueOf(vfId));
        }
        vfDtlQueryCondition.setVfTypCd(CapitalConstant.CODE_VF_TYP_CD_1);//核销
        List<CapFundVfDtlVO> vfDtlList = this.capFundVfDtlService.searchList(vfDtlQueryCondition);

        List<KeyValueVO> keyValueVOList =  sysDictionaryApiService.getKvListWithAttr1(DictionaryConstant.CODE_PRJ_QUAT_FEE_SETT_TYP_CD, DictionaryConstant.SYS_DIC_FILTER_CODE_ATTR1_CD_2, CurrentThreadContext.getFlServiceSysCd(),CurrentThreadContext.getCurrentOrgCd());//SystemConstant.FL_SERVICE_CD, SystemConstant.FL_ORG_CD);
        Map<String,String> feeTypMap = null ;
        if(CollectionUtils.isNotEmpty(keyValueVOList)){
            feeTypMap = new HashMap<>();
            for(KeyValueVO keyValueVO : keyValueVOList){
                feeTypMap.put(keyValueVO.getKey(),keyValueVO.getValue());
            }
        }

        if(CollectionUtils.isNotEmpty(vfDtlList)){
            for(CapFundVfDtlVO vo : vfDtlList){
                if(StringUtils.isNotBlank(vo.getFeeTypCd()) && CollectionUtils.isMapNotEmpty(feeTypMap)){
                    if(feeTypMap.containsKey(vo.getFeeTypCd()) && vo.getVfAmt() > 0){
                        vo.setVfAmt(-vo.getVfAmt());
                    }
                }
            }
        }

        CapFundVO fundVO = null;
        if (StringUtils.isNotEmpty(fundId)) {
            fundVO = this.capFundService.selectById(Long.valueOf(fundId));
        } else {
            if (CollectionUtils.isNotEmpty(vfDtlList)) {
                fundVO = this.capFundService.selectById(vfDtlList.get(0).getFundId());
            }
        }

        if (null == fundVO) {
            return;
        } else {
            if (null != fundVO.getAcceptDate()) {
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            }
        }

        //修改导出状态
        //fundVO.setExpStatusCd("1");//导出状态 0.未导出 1.已导出
        //this.capFundService.modify(fundVO);

        Map<String, Object> map = new HashMap<>();
        map.put("CapFund", fundVO);
        map.put("FundList", vfDtlList);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String filename = "分解单导出";
        response.setCharacterEncoding("utf-8");
        OutputStream os = null;
        try {
            filename = new String(filename.getBytes("utf-8"), "ISO8859-1");
            response.setHeader("Content-disposition", "attachment; filename=" + filename + ".pdf");// 设定输出文件头
            response.setContentType("application/pdf");// 定义输出类型
            baos = new ExportFundList().exportDecomPdf(map);
            os = response.getOutputStream();
            baos.writeTo(os);
            baos.flush();
            os.flush();
        } catch (UnsupportedEncodingException e) {
            BaseLogUtils.newLogger("异常").setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
        } catch (IOException e) {
            BaseLogUtils.newLogger("异常").setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
        } finally {
            //关闭流
            if (os != null) {
                try {
                    os.close();
                } catch (IOException e) {
                    BaseLogUtils.newLogger("异常").setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
                }
            }
            if (baos != null) {
                try {
                    baos.close();
                } catch (IOException e) {
                    BaseLogUtils.newLogger("异常").setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
                }
            }

        }
    }

    /****************************
     * 导出资金分解支付表明细
     ****************************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportDecomList.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportDecomList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("批量导出资金分解明细" ).setKeys("exportDecomList",CurrentThreadContext.getCurrentUserName()).info();
        CapFundVfLogExportCondition qc = new CapFundVfLogExportCondition();
        String vfNo = request.getParameter("vfNo");//分解单号、冲红单号
        String fundCd = request.getParameter("fundCd");//资金编号
        String acceptCode = request.getParameter("acceptCode");//收款账号
        String acceptName = request.getParameter("acceptName");//收款户名
        String comeCode = request.getParameter("comeCode");//来款账号
        String comeName = request.getParameter("comeName");//来款账户
        String acceptDateMin = request.getParameter("acceptDateMin");//来款时间
        String acceptDateMax = request.getParameter("acceptDateMax");//来款时间
        String acceptActualDateMin = request.getParameter("acceptActualDateMin");//到账时间
        String acceptActualDateMax = request.getParameter("acceptActualDateMax");//到账时间
        String cstNm = request.getParameter("cstNm");//客户名称
        String vfUsrNm = request.getParameter("vfUsrNm");//分解人名称
        String vfUsrId = request.getParameter("vfUsrId");//分解人ID
        String vfTmMin = request.getParameter("vfTmMin");//核销最小时间
        String vfTmMax = request.getParameter("vfTmMax");//核销最大时间
        String vfTypCd = request.getParameter("vfTypCd");//核销类型 1.核销 2.冲红 3.减免

        if (StringUtils.isNotBlank(vfTypCd)) {
            qc.setVfTypCd(vfTypCd);
        }
        if (StringUtils.isNotBlank(vfNo)) {
            qc.setVfNo(vfNo.trim());
        }
        if (StringUtils.isNotBlank(fundCd)) {
            qc.setFundCd(fundCd.trim());
        }
        if (StringUtils.isNotBlank(vfUsrId)) {
            qc.setVfUsrId(Long.valueOf(vfUsrId));
        }
        if (StringUtils.isNotBlank(vfUsrNm)) {
            qc.setVfUsrNm(vfUsrNm.trim());
        }
        if (StringUtils.isNotBlank(acceptCode)) {
            qc.setAcceptCode(acceptCode.trim());
        }
        if (StringUtils.isNotBlank(acceptName)) {
            qc.setAcceptName(acceptName.trim());
        }
        if (StringUtils.isNotBlank(comeCode)) {
            qc.setComeCode(comeCode.trim());
        }
        if (StringUtils.isNotBlank(comeName)) {
            qc.setComeName(comeName.trim());
        }
        if (StringUtils.isNotBlank(vfTmMax)) {
            qc.setVfTmMax(vfTmMax.trim());
        }
        if (StringUtils.isNotBlank(vfTmMin)) {
            qc.setVfTmMin(vfTmMin.trim());
        }
        if (StringUtils.isNotBlank(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotBlank(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotBlank(acceptActualDateMax)) {
            qc.setAcceptActualDateMax(acceptActualDateMax);
        }
        if (StringUtils.isNotBlank(acceptActualDateMin)) {
            qc.setAcceptActualDateMin(acceptActualDateMin);
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm.trim());
        }
        return this.capFundVfLogService.exportDecomposeList(qc);
    }

    /**
     * 资金分解，查询待分解支付表明细+罚息  来款手动核销页面
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/searchBillItemList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object searchBillItemList(HttpServletRequest request, HttpServletResponse response) {
        String cstId = request.getParameter("cstId");//客户ID
        String acceptActualDate = request.getParameter("acceptActualDate");//实际到账日期
        String payPd = request.getParameter("payPd");//期次，首期款核销
        String type = request.getParameter("type");//

        CapFundQueryCondition qc = new CapFundQueryCondition();
        if (StringUtils.isNotBlank(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotBlank(acceptActualDate)) {
            qc.setAcceptActualDate(DateUtils.formatStringToDate(acceptActualDate, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(payPd)) {
            qc.setPayPd(Long.valueOf(payPd));
        }
        if (StringUtils.isNotEmpty(type)) {
            qc.setType(type);
        }

        List<BillItemVO> billItemVOList = this.capFundService.queryBillItemList(qc);
        if (CollectionUtils.isNotEmpty(billItemVOList)) {
            ListPageVO<BillItemVO> listPageVO = new ListPageVO<>(billItemVOList, billItemVOList.size());
            return listPageVO;
        }
        return null;
    }


    /**
     * 资金分解，查询待分解支付表明细+罚息  来款手动核销页面
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/searchPaySchDList.do", method = {RequestMethod.GET})
    @ResponseBody
    @Deprecated
    public Object searchPaySchDList(HttpServletRequest request, HttpServletResponse response) {
        String cstId = request.getParameter("cstId");//客户ID
        String acceptActualDate = request.getParameter("acceptActualDate");//实际到账日期
        String payPd = request.getParameter("payPd");//期次，首期款核销
        String type = request.getParameter("type");//

        CapFundQueryCondition qc = new CapFundQueryCondition();
        if (StringUtils.isNotBlank(cstId)) {
            qc.setCstId(Long.valueOf(cstId));
        }
        if (StringUtils.isNotBlank(acceptActualDate)) {
            qc.setAcceptActualDate(DateUtils.formatStringToDate(acceptActualDate, DateUtils.YYYY_MM_DD));
        }
        if (StringUtils.isNotEmpty(payPd)) {
            qc.setPayPd(Long.valueOf(payPd));
        }
        if (StringUtils.isNotEmpty(type)) {
            qc.setType(type);
        }

        //查询待分解支付表+罚息toAddFundPage.do
        List<PrjPrdPaySchDVO> voList = this.capFundService.searchPaySchDList(qc);
        if (CollectionUtils.isNotEmpty(voList)) {
            ListPageVO<PrjPrdPaySchDVO> listPageVO = new ListPageVO<PrjPrdPaySchDVO>(voList, voList.size());
            return listPageVO;
        }
        return null;
    }


    /**********************************
     * 到资金分解/冲红详情页面
     **********************************/
    @RequestMapping(value = "/toDecomDtlPage.do", method = {RequestMethod.GET})
    public ModelAndView toFundDecomDtlPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资金分解单详情页面" ).setKeys("toFundDecomDtlPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundDecomDtl");
        String fundId = request.getParameter("fundId");//资金ID
        String vfId = request.getParameter("vfId");//分解单ID、冲红记录ID
        if (StringUtils.isEmpty(fundId) && StringUtils.isEmpty(vfId)) {
            BaseLogUtils.newLogger("加载资金分解单详情页面,资金ID和分解ID为空" ).setKeys("toFundDecomDtlPage",CurrentThreadContext.getCurrentUserName()).info();
            return mav;
        }
        Long fid = 0L;//资金ID
        if (StringUtils.isEmpty(fundId)) {
            CapFundVfLogVO capFundVfLogVO = capFundVfLogService.selectById(Long.valueOf(vfId));//查询分解、冲红记录
            fid = capFundVfLogVO.getFundId();
        } else {
            fid = Long.valueOf(fundId);
        }
        CapFundVO fundVO = capFundService.selectById(fid);
        if (fundVO != null) {
            if (fundVO.getAcceptDate() != null) {
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            }
            if (fundVO.getAcceptActualDate() != null) {
                fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
            }
        }

        mav.addObject("capFundVO", fundVO);
        mav.addObject("vfId", vfId);
        return mav;
    }

    /**********************************
     * 查询资金分解明细
     **********************************/
    @RequestMapping(value = "/searchVfDtlList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object searchDecomDtlList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资金分解单详情" ).setKeys("searchDecomDtlList",CurrentThreadContext.getCurrentUserName()).info();
        String fundId = request.getParameter("fundId");//资金ID
        String vfId = request.getParameter("vfId");//分解Id
        String vfTypCd = request.getParameter("vfTypCd");//核销类型

        CapFundVfDtlQueryCondition vfDtlQueryCondition = new CapFundVfDtlQueryCondition();
        if (StringUtils.isNotEmpty(fundId)) {//资金ID
            vfDtlQueryCondition.setFundId(Long.valueOf(fundId));
        }
        if (StringUtils.isNotBlank(vfId)) {
            vfDtlQueryCondition.setVfId(Long.valueOf(vfId));
        }
        if (StringUtils.isNotBlank(vfTypCd)) {
            vfDtlQueryCondition.setVfTypCd(vfTypCd);//1.核销 2.冲红 3.减免
        }

        List<CapFundVfDtlVO> vfDtlList = this.capFundVfDtlService.searchList(vfDtlQueryCondition);
        if(CollectionUtils.isNotEmpty(vfDtlList)){
            for(CapFundVfDtlVO vo : vfDtlList){
                if(StringUtils.isNotBlank(vo.getCapFlow())&&CapitalConstant.CODE_CAP_FLOW_2.equals(vo.getCapFlow())){//支出为负
                    if(StringUtils.isNotEmpty(vo.getPayFeeAmt())){
                        vo.setPayFeeAmt(-vo.getPayFeeAmt());
                    }
                    if(StringUtils.isNotEmpty(vo.getVfAmt())){
                        vo.setVfAmt(-vo.getVfAmt());
                    }
                }
            }
            return new ListPageVO<CapFundVfDtlVO>(vfDtlList, vfDtlList.size());
        }else{
            return new ListPageVO<CapFundVfDtlVO>(new ArrayList<CapFundVfDtlVO>(0), 0);
        }
    }

    /**********************************
     * 查询资金分解、冲红记录
     **********************************/
    @RequestMapping(value = "/searchVfLogList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object searchVfLogList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载资金分解、冲红记录列表页面" ).setKeys("searchVfLogList",CurrentThreadContext.getCurrentUserName()).info();
        String fundId = request.getParameter("fundId");//资金ID
        String vfId = request.getParameter("vfId");//分解Id
        String vfTypCd = request.getParameter("vfTypCd");//核销方式
        CapFundVfLogQueryCondition vfLogQueryCondition = new CapFundVfLogQueryCondition();
        if (StringUtils.isNotEmpty(fundId)) {//资金ID
            vfLogQueryCondition.setFundId(Long.valueOf(fundId));
        }
        if (StringUtils.isNotBlank(vfId)) {
            vfLogQueryCondition.setId(Long.valueOf(vfId));
        }
        if (StringUtils.isNotBlank(vfTypCd)) {
            vfLogQueryCondition.setVfTypCd(vfTypCd);//核销、冲红
        }
        List<CapFundVfLogVO> vfLogList = this.capFundVfLogService.searchList(vfLogQueryCondition);
        ListPageVO<CapFundVfLogVO> listPage = new ListPageVO<CapFundVfLogVO>(vfLogList, vfLogList.size());
        return listPage;
    }

    /**********************************
     * 到分解单冲红申请页面
     **********************************/
    @RequestMapping(value = "/toRevertFundPage.do", method = {RequestMethod.GET})
    public ModelAndView toRevertFundPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到分解单冲红申请页面" ).setKeys("toRevertFundPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capRevertFund");
        String vfId = request.getParameter("vfId");//分解单ID
        String fundId = request.getParameter("fundId");
        if (StringUtils.isEmpty(fundId)) {
            BaseLogUtils.newLogger("到分解单冲红申请页面,分解、冲红单号为空" ).setKeys("toRevertFundPage",CurrentThreadContext.getCurrentUserName()).info();
            return mav;
        }
        CapFundVO fundVO = capFundService.selectById(Long.parseLong(fundId));
        CapFundVfLogVO capFundVfLogVO = capFundVfLogService.selectById(Long.valueOf(vfId));//查询分解、冲红记录
        if (fundVO != null) {
            if (fundVO.getAcceptDate() != null) {
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            }
            if (fundVO.getAcceptActualDate() != null) {
                fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
            }
            fundVO.setFundDecomUsrNm(capFundVfLogVO.getVfUsrNm());
        }

        mav.addObject("capFundVO", fundVO);
        mav.addObject("vfId", vfId);

        return mav;
    }

    /*********************
     * 冲红申请
     *********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/revertFundApply.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO revertFundApply(HttpServletRequest request, HttpServletResponse response) {
        String ids = request.getParameter("ids");//分解明细ID
        String fundId = request.getParameter("fundId");//资金ID
        String vfRem = request.getParameter("vfRem");//冲红原因备注
        String vfId = request.getParameter("vfId");//分解ID
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.newLogger("冲红申请,冲红的分解单明细参数为空" ).setKeys("revertFundApply",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }

        CapFundVfDtlQueryCondition vfDtlQueryCondition = new CapFundVfDtlQueryCondition();
        if (StringUtils.isNotEmpty(fundId)) {
            vfDtlQueryCondition.setFundId(Long.valueOf(fundId));
        }
        vfDtlQueryCondition.setVfUsrId(CurrentThreadContext.getCurrentUserId());
        vfDtlQueryCondition.setVfUsrNm(CurrentThreadContext.getCurrentUserName());
        vfDtlQueryCondition.setVfRem(vfRem);//冲红原因
        if (StringUtils.isNotEmpty(vfId)) {
            vfDtlQueryCondition.setVfId(Long.valueOf(vfId));
        }
        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }
        vfDtlQueryCondition.setIdList(idsList);
        vfDtlQueryCondition.setBuOrgCd(CurrentThreadContext.getCurrentOrgCd());

        try {
            result = this.capFundVfDtlService.modifyFundRevert(vfDtlQueryCondition);
            BaseLogUtils.newLogger("冲红申请返回DATA:" + JSON.toJSONString(result)).setKeys("revertFundApply",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("冲红申请失败.DATA:" + JSONObject.toJSONString(vfDtlQueryCondition)).setKeys("revertFundApply",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("冲红申请失败,系统错误.DATA:" + JSONObject.toJSONString(vfDtlQueryCondition)).setKeys("revertFundApply",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /******************************
     * 初始化核销列表
     ******************************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initVfList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initVfList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        CapFundVfLogQueryCondition qc = new CapFundVfLogQueryCondition();
        String vfNo = request.getParameter("vfNo");//分解单号、冲红单号
        String fundCd = request.getParameter("fundCd");//资金编号
        String acceptCode = request.getParameter("acceptCode");//收款账号
        String acceptName = request.getParameter("acceptName");//收款户名
        String comeCode = request.getParameter("comeCode");//来款账号
        String comeName = request.getParameter("comeName");//来款账户
        String acceptDateMin = request.getParameter("acceptDateMin");//来款时间
        String acceptDateMax = request.getParameter("acceptDateMax");//来款时间
        String acceptActualDateMin = request.getParameter("acceptActualDateMin");//到账时间
        String acceptActualDateMax = request.getParameter("acceptActualDateMax");//到账时间
        String cstNm = request.getParameter("cstNm");//客户名称
        String vfUsrNm = request.getParameter("vfUsrNm");//分解人名称
        String vfUsrId = request.getParameter("vfUsrId");//分解人ID
        String vfTmMin = request.getParameter("vfTmMin");//核销最小时间
        String vfTmMax = request.getParameter("vfTmMax");//核销最大时间
        String vfTypCd = request.getParameter("vfTypCd");//核销类型 1.核销 2.冲红 3.减免

        if (StringUtils.isNotBlank(vfTypCd)) {
            qc.setVfTypCd(vfTypCd);
        }
        if (StringUtils.isNotBlank(vfNo)) {
            qc.setVfNo(vfNo.trim());
        }
        if (StringUtils.isNotBlank(fundCd)) {
            qc.setFundCd(fundCd.trim());
        }
        if (StringUtils.isNotBlank(vfUsrId)) {
            qc.setVfUsrId(Long.valueOf(vfUsrId));
        }
        if (StringUtils.isNotBlank(vfUsrNm)) {
            qc.setVfUsrNm(vfUsrNm.trim());
        }
        if (StringUtils.isNotBlank(acceptCode)) {
            qc.setAcceptCode(acceptCode.trim());
        }
        if (StringUtils.isNotBlank(acceptName)) {
            qc.setAcceptName(acceptName.trim());
        }
        if (StringUtils.isNotBlank(comeCode)) {
            qc.setComeCode(comeCode.trim());
        }
        if (StringUtils.isNotBlank(comeName)) {
            qc.setComeName(comeName.trim());
        }
        if (StringUtils.isNotBlank(vfTmMax)) {
            qc.setVfTmMax(vfTmMax.trim());
        }
        if (StringUtils.isNotBlank(vfTmMin)) {
            qc.setVfTmMin(vfTmMin.trim());
        }
        if (StringUtils.isNotBlank(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotBlank(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotBlank(acceptActualDateMax)) {
            qc.setAcceptActualDateMax(acceptActualDateMax);
        }
        if (StringUtils.isNotBlank(acceptActualDateMin)) {
            qc.setAcceptActualDateMin(acceptActualDateMin);
        }
        if (StringUtils.isNotBlank(cstNm)) {
            qc.setCstNm(cstNm.trim());
        }
        page.setCondition(qc);

        BaseLogUtils.newLogger("初始化核销列表页面数据.DATA:" + JSONObject.toJSONString(page)).setKeys("initVfList",CurrentThreadContext.getCurrentUserName()).info();
        Pager pager = this.capFundVfLogService.searchListPage(page);
        List<CapFundVfLogVO> list = (List<CapFundVfLogVO>) pager.getResultList();
        ListPageVO<CapFundVfLogVO> listPage = new ListPageVO<CapFundVfLogVO>(list, pager.getTotalCount());
        return listPage;
    }

    /******************************
     * 初始化核销列表
     ******************************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/initCstList.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object initCstList(HttpServletRequest request, HttpServletResponse response) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }
        // 查询条件
        String cstNm = request.getParameter("cstNm");
        String lsCntNo = request.getParameter("lsCntNo");//合同号
        String paySchNo = request.getParameter("paySchNo");//支付表号
        String opTyp = request.getParameter("opTyp");//操作类型 1.财务认款 2.客户经理认款
        if(StringUtils.isBlank(cstNm)){
            return new ListPageVO<CapPayInfoVO>(new ArrayList<CapPayInfoVO>(0), 0);
        }

        CapFundQueryCondition condition = new CapFundQueryCondition();
        if (StringUtils.isNotBlank(cstNm)) {
            condition.setCstNm(cstNm.trim());
        }
        if (StringUtils.isNotBlank(lsCntNo)) {
            condition.setAdditionalCondition(lsCntNo.trim());
        }
        if(StringUtils.isNotBlank(paySchNo)){
            condition.setPaySchNo(paySchNo.trim());
        }
        if(StringUtils.isNotBlank(opTyp)){
            condition.setOpTyp(opTyp);
        }

        page.setCondition(condition);
        BaseLogUtils.newLogger("初始化列表数据.Condition:" + JSON.toJSONString(condition)).setKeys("initCstList",CurrentThreadContext.getCurrentUserName()).info();
        Pager pager = this.capFundService.searchCstListPage(page);
        List<CapPayInfoVO> list = (List<CapPayInfoVO>) pager.getResultList();
        ListPageVO<CapPayInfoVO> listPage = new ListPageVO<CapPayInfoVO>(list, pager.getTotalCount());
        return listPage;
    }


    /**************************
     * 到冲红申请列表页面
     **************************/
    @RequestMapping(value = "/toRevertFundListPage.do", method = {RequestMethod.GET})
    public ModelAndView toRevertFundListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到冲红申请列表页面" ).setKeys("toRevertFundListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capRedApplyList");
        return mav;
    }

    /**************************
     * 到分解单管理页面
     **************************/
    @RequestMapping(value = "/toDecomListPage.do", method = {RequestMethod.GET})
    public ModelAndView toDecomListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到分解单管理capDecomList页面" ).setKeys("toDecomListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capDecomList");
        return mav;
    }

    /**************************
     * 到分解单管理页面（总）
     **************************/
    @RequestMapping(value = "/toDecomPage.do", method = {RequestMethod.GET})
    public ModelAndView toDecomPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到分解单capDecom页面 （总）" ).setKeys("toDecomPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capDecom");
        return mav;
    }

    /**************************
     * 到分解单详细页面
     **************************/
    @RequestMapping(value = "/toDecomDtlListPage.do", method = {RequestMethod.GET})
    public ModelAndView toDecomDtlListPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到分解单capDecomDtl详细页面" ).setKeys("toDecomDtlListPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capDecomDtl");
    	//事业部
		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
		mav.addObject("buOrgCdList", JSON.toJSONString(orgList));
        return mav;
    }

    /****************************************************
     * 到首期款核销-添加资金页面;
     * 重卡正常、提前、特殊放款-会计核销首期款 /capital/capFund/toAddFundPage.do?payId=
     ****************************************************/
    @RequestMapping(value = "/toAddFundPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddFundPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到首期款核销-添加资金页面" ).setKeys("toAddFundPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFstFundModify");
        this.prepare(request, mav);
        String payId = request.getParameter("payId");//付款ID
        String prjId = request.getParameter("prjId");//项目ID
        if (StringUtils.isEmpty(payId) && StringUtils.isEmpty(prjId)) {
            BaseLogUtils.newLogger("到首期款核销-添加资金Error:付款ID和项目ID为空" ).setKeys("toAddFundPage",CurrentThreadContext.getCurrentUserName()).info();
            return mav;
        }

        CapPayInfoVO payInfoVO = null;//付款信息
        List<Long> paySchIdList = null;//支付表ID集合
        if (StringUtils.isNotEmpty(payId)) {
            payInfoVO = this.capPayInfoService.selectById(Long.valueOf(payId));
            paySchIdList = new ArrayList<>(1);
            paySchIdList.add(payInfoVO.getPaySchId());//支付表ID
        } else {
            CapPayInfoQueryCondition condition = new CapPayInfoQueryCondition();
            condition.setPrjId(Long.valueOf(prjId));
            List<CapPayInfoVO> payInfoList = capPayInfoService.searchList(condition);
            if (CollectionUtils.isNotEmpty(payInfoList)) {
                payInfoVO = payInfoList.get(0);
                paySchIdList = new ArrayList<>(payInfoList.size());
                for (CapPayInfoVO vo : payInfoList) {
                    paySchIdList.add(vo.getPaySchId());//支付表ID
                }
            } else {
                BaseLogUtils.newLogger("到首期款核销-添加资金Error:未找到项目对应的放款信息" ).setKeys("toAddFundPage",CurrentThreadContext.getCurrentUserName()).info();
                return mav;
            }
        }

        mav.addObject("payInfo", payInfoVO);
        if (null != payInfoVO) {
            //mav.addObject("amount",DecimalUtils.convertFenToYuan(payInfoVO.getInitPayAmt()));
            //根据支付表ID查询首期款明细
            CapFundQueryCondition qc = new CapFundQueryCondition();
            qc.setPayPd(0l);//首期款
            //qc.setPaySchId(payInfoVO.getPaySchId());//支付表ID
            qc.setPaySchIdList(paySchIdList);//支付表ID集合
            qc.setCstId(payInfoVO.getCstId());
            //查询支付表首期款费用明细
            List<PrjPrdPaySchDVO> voList = this.capFundService.searchFstPayList(qc);
            Double fundAmt = 0d;//来款金额
            if (CollectionUtils.isNotEmpty(voList)) {
                for (PrjPrdPaySchDVO vo : voList) {
                    fundAmt += vo.getFeeAmt();
                }
                mav.addObject("paySchList", JSON.toJSONString(voList));
            }
            mav.addObject("amount", DecimalUtils.convertFenToYuan(fundAmt.longValue()));//应收首付款金额

            //查询客户资金
            CapFundQueryCondition fundQueryCondition = new CapFundQueryCondition();
            fundQueryCondition.setCstId(payInfoVO.getCstId());//客户ID
            if (StringUtils.isNotEmpty(payId)) {
                fundQueryCondition.setRelationPayId(Long.valueOf(payId));//付款ID
            } else {
                fundQueryCondition.setRelationPayId(Long.valueOf(prjId));//项目ID
            }
            //fundQueryCondition.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//未分解
            List<CapFundVO> fundList = this.capFundService.searchList(fundQueryCondition);
            CapFundVO fundVO = null;
            if (CollectionUtils.isNotEmpty(fundList)) {
                fundVO = fundList.get(0);//不会出现多笔资金？
                mav.addObject("amount", DecimalUtils.convertFenToYuan(fundVO.getAmount()));//应收首付款金额，已录入来款金额
                //查询分解人、制作人, 暂时根据资金编号查询资金核销记录中的核销人
                CapFundVfLogQueryCondition vfLogQueryCondition = new CapFundVfLogQueryCondition();
                vfLogQueryCondition.setFundId(fundVO.getId());
                vfLogQueryCondition.setVfTypCd(CapitalConstant.CODE_VF_TYP_CD_1);
                List<CapFundVfLogVO> vfLogList = capFundVfLogService.searchList(vfLogQueryCondition);
                if (CollectionUtils.isNotEmpty(vfLogList)) {
                    CapFundVfLogVO vfLogVO = vfLogList.get(0);
                    mav.addObject("vfUsrNm", vfLogVO.getVfUsrNm());
                }
            } else {
                fundVO = new CapFundVO();
                fundVO.setComeName(payInfoVO.getCstNm());//客户名称=来款人
                if (StringUtils.isNotEmpty(payId)) {
                    fundVO.setRelationPayId(Long.valueOf(payId));//资金管理关联付款ID
                } else {
                    fundVO.setRelationPayId(Long.valueOf(prjId));//资金管理关联项目ID
                }
                fundVO.setCstId(payInfoVO.getCstId());//客户ID
                fundVO.setCstNm(payInfoVO.getCstNm());//客户名称
                fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
                fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
                fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
                fundVO.setFundBelongOrgCd(payInfoVO.getBuOrgCd());//所属事业部
                //默认财务收款账户、账号
                fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
                fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
                //交易日期与实际到账日期默认流程发起时间
                if (null != payInfoVO.getFlowStartTm()) {
                    fundVO.setAcceptDate(DateUtils.formatDate(payInfoVO.getFlowStartTm(), DateUtils.YYYY_MM_DD));
                    fundVO.setAcceptActualDate(DateUtils.formatDate(payInfoVO.getFlowStartTm(), DateUtils.YYYY_MM_DD));
                }
            }
            if (fundVO.getAcceptDate() != null) {
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            }
            if (fundVO.getAcceptActualDate() != null) {
                fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
            }
            fundVO.setPaySchNo(payInfoVO.getPaySchNo());
            mav.addObject("capFundVO", fundVO);

        }
        return mav;

    }

    /**
     * 到添加风险保证金页面
     * 到添加支付表费用-添加资金页面
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toAddFeePage.do", method = {RequestMethod.GET})
    public ModelAndView toAddFeePage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到添加支付表费用-添加资金页面" ).setKeys("toAddFeePage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFstFundModify");
        this.prepare(request, mav);
        String dtlId = request.getParameter("dtlId");//支付表明细ID
        if (StringUtils.isEmpty(dtlId)) {
            BaseLogUtils.newLogger("到添加支付表费用-添加资金Error:支付表明细ID为空" ).setKeys("toAddFeePage",CurrentThreadContext.getCurrentUserName()).info();
            return mav;
        }

        //查询支付表明细
        PrjPrdPaySchDVO prjPrdPaySchDVO = this.prjPrdPaySchDService.selectById(Long.parseLong(dtlId));
        if (prjPrdPaySchDVO != null) {
            String feeTypCdNm = this.capFundService.getFeeTypCdNm(prjPrdPaySchDVO.getFeeTypCd());
            if(StringUtils.isNotBlank(feeTypCdNm)){
                prjPrdPaySchDVO.setFeeTypCdNm(feeTypCdNm);
            }else{
                prjPrdPaySchDVO.setFeeTypCdNm("风险保证金");
            }

            //根据支付表ID查询支付表主信息
            PrjPrdPaySchMVO prjPrdPaySchMVO = this.prjPrdPaySchMService.selectById(prjPrdPaySchDVO.getPaySchId());
            //查询客户资金
            CapFundQueryCondition fundQueryCondition = new CapFundQueryCondition();
            fundQueryCondition.setRelationPayId(Long.parseLong(dtlId));//支付表明细ID
            if (prjPrdPaySchMVO != null) {
                fundQueryCondition.setCstId(prjPrdPaySchMVO.getCstId());
                prjPrdPaySchDVO.setPaySchNo(prjPrdPaySchMVO.getPaySchNo());
            }
            List<PrjPrdPaySchDVO> voList = new ArrayList<>(1);
            voList.add(prjPrdPaySchDVO);
            mav.addObject("paySchList", JSON.toJSONString(voList));
            mav.addObject("amount", DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt().longValue()));//应收金额

            List<CapFundVO> fundList = this.capFundService.searchList(fundQueryCondition);
            CapFundVO fundVO = null;
            if (CollectionUtils.isNotEmpty(fundList)) {
                fundVO = fundList.get(0);//不会出现多笔资金？
                mav.addObject("amount", DecimalUtils.convertFenToYuan(fundVO.getAmount()));//应收首付款金额，已录入来款金额
                //查询分解人、制作人, 暂时根据资金编号查询资金核销记录中的核销人
                CapFundVfLogQueryCondition vfLogQueryCondition = new CapFundVfLogQueryCondition();
                vfLogQueryCondition.setFundId(fundVO.getId());
                vfLogQueryCondition.setVfTypCd(CapitalConstant.CODE_VF_TYP_CD_1);
                List<CapFundVfLogVO> vfLogList = capFundVfLogService.searchList(vfLogQueryCondition);
                if (CollectionUtils.isNotEmpty(vfLogList)) {
                    CapFundVfLogVO vfLogVO = vfLogList.get(0);
                    mav.addObject("vfUsrNm", vfLogVO.getVfUsrNm());
                }
            } else {
                fundVO = new CapFundVO();
                if (prjPrdPaySchMVO != null) {
                    PrjBscInfoVO prjBscInfoVO = prjBscInfoService.selectById(prjPrdPaySchMVO.getPrjId());
                    if (prjBscInfoVO != null) {
                        fundVO.setComeName(prjBscInfoVO.getCstNm());//客户名称=来款人
                        fundVO.setRelationPayId(prjPrdPaySchDVO.getId());//资金管理关联ID
                        fundVO.setCstId(prjBscInfoVO.getCstId());//客户ID
                        fundVO.setCstNm(prjBscInfoVO.getCstNm());//客户名称
                        fundVO.setFundBelongOrgCd(prjBscInfoVO.getBuOrgCd());//所属事业部
                    }
                }
                fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
                fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
                fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
                if (CapitalConstant.CODE_PRJ_FEE_TYP_CD_33.equals(prjPrdPaySchDVO.getFeeTypCd())) {
                    fundVO.setFundSourcesCd(CapitalConstant.CODE_FUND_SRC_CD_6);
                }

                //默认财务收款账户、账号
                fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
                fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
                //交易日期与实际到账日期默认流程发起时间
                Date flowStartTm = this.capFundService.getAddFeeFlowStartTime(prjPrdPaySchDVO);
                if (null != flowStartTm) {
                    fundVO.setAcceptDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
                    fundVO.setAcceptActualDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
                }
            }
            if (fundVO.getAcceptDate() != null) {
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
            }
            if (fundVO.getAcceptActualDate() != null) {
                fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
            }
            if (prjPrdPaySchMVO != null) {
                fundVO.setPaySchNo(prjPrdPaySchMVO.getPaySchNo());
            }
            mav.addObject("capFundVO", fundVO);
        }
        return mav;
    }


    /****************************************************
     * 到录入来款页面，支持录入多笔来款;
     ****************************************************/
    @RequestMapping(value = "/toAddCapFundPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddCapFundPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("到录入来款页面" ).setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/capFundAdd");
        this.prepare(request, mav);
        //业务主键：1.放款->付款ID；2.添加风险保证金->支付表明细ID； 3.结清->支付表ID；4.保险保证金->保单ID
        String bizTyp = request.getParameter("bizTyp");//业务类型 3
        String dataId = request.getParameter("dataId");//业务主键
        String outFlag = request.getParameter("outFlag");//保证金转出标示 1.是 0.否
        if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(bizTyp)) {
            BaseLogUtils.newLogger("到录入来款页面Error:业务主键或类型为空" ).setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
            return mav;
        }
        CapFundVO fundVO = null;//来款信息
        //流程中录入来款业务类型:1.放款 2.添加风险保证金 3.结清
        if (CapitalConstant.CODE_BIZ_TYP_CD_1.equals(bizTyp)) {
            BaseLogUtils.newLogger("到首期款核销录入来款页面" ).setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
        } else if (CapitalConstant.CODE_BIZ_TYP_CD_2.equals(bizTyp)) {
            BaseLogUtils.newLogger("到添加添加风险保证金录入来款页面" ).setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
        } else if (CapitalConstant.CODE_BIZ_TYP_CD_3.equals(bizTyp)) {
            String isMdfPaySch = request.getParameter("isMdfPaySch");
            String stlDtFlag = request.getParameter("stlDtFlag");//1.显示结清时间维护 2.不显示结清时间维护
            // (created by REQ-9253 自动退款)
            String isDetail_bk = request.getParameter("isDetail_bk");//标识是否详情
            String showBk_oCIn = request.getParameter("showBk_oCIn");//加载我司收款账号维护页面
            String showBk_oCOut = request.getParameter("showBk_oCOut");//加载我司付款账号维护页面
            String editInto = request.getParameter("editInto");//我司付款_维护收款账号
            String editOut = request.getParameter("editOut");//我司付款_维护付款账号
            //查询支付表信息
            PrjPrdPaySchMVO paySchMVO = this.prjPrdPaySchMService.selectById(Long.parseLong(dataId));
            if (paySchMVO == null) {
                BaseLogUtils.newLogger("到结清录入来款页面,未找到支付表[" + dataId + "]信息.").setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
                return mav;
            }
            //查询项目信息
            PrjBscInfoVO prjBscInfoVO = this.prjBscInfoService.selectById(paySchMVO.getPrjId());
            if (prjBscInfoVO == null) {
                BaseLogUtils.newLogger("到结清录入来款页面,未找到支付表[" + dataId + "]对应项目信息.").setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
                return mav;
            }
            if (StringUtils.isNotBlank(isMdfPaySch) && "1".equals(isMdfPaySch)) {
                boolean flag = this.capFundService.modifyPaySchById(Long.parseLong(dataId));
                BaseLogUtils.newLogger("到结清录入来款页面前修改支付表==" + flag).setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
                if(flag && StringUtils.isNotBlank(prjBscInfoVO.getPrjTypCd()) && "ZZKP".equals(prjBscInfoVO.getPrjTypCd())){
                    flag = this.prjPrdPaySchMApiService.modifyAndRemovePrjPrdPaySchTMByPaySchId(paySchMVO.getId());
                    if(!flag){
                        throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "操作有误!车立行支付表数据处理错误!");
                    }
                }
            }
            if (StringUtils.isNotBlank(stlDtFlag) && "2".equals(isMdfPaySch)) {
                mav.addObject("stlDtlFlag", "2");//2.不显示结清时间维护
            } else {
                mav.addObject("stlDtlFlag", "1");//1.显示结清时间维护
            }

            BaseLogUtils.newLogger("到结清录入来款页面").setKeys("toAddCapFundPage",CurrentThreadContext.getCurrentUserName()).info();
            fundVO = new CapFundVO();
            fundVO.setRelationPayId(Long.parseLong(dataId));//资金管理关联业务ID
            fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
            fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
            fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
            //默认财务收款账户、账号
            fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
            fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
            fundVO.setPaySchNo(paySchMVO.getPaySchNo());

            //查询客户名称，客户ID,所属事业部
            fundVO.setCstId(paySchMVO.getCstId());
            fundVO.setCstNm(prjBscInfoVO.getCstNm());
            fundVO.setFundBelongOrgCd(prjBscInfoVO.getBuOrgCd());
            fundVO.setComeName(prjBscInfoVO.getCstNm());

            //查询待核销支付表明细列表 支付表号、客户ID、期次、费用类型
            mav.addObject("paySchId", paySchMVO.getId());
            mav.addObject("cstId", fundVO.getCstId());

            mav.addObject("showBk_oCIn", showBk_oCIn);
            mav.addObject("showBk_oCOut", showBk_oCOut);
            mav.addObject("editInto", editInto);
            mav.addObject("editOut", editOut);
            mav.addObject("isDetail_bk", isDetail_bk);
            mav.addObject("pay", paySchMVO);

            //交易日期与实际到账日期默认流程发起时间
            Date flowStartTm = this.capFundService.getFlowStartTime(Long.parseLong(dataId), bizTyp);
            if (null != flowStartTm) {
                fundVO.setAcceptDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
                fundVO.setAcceptActualDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
                fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
                fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
            }

            CapFundQueryCondition qc = new CapFundQueryCondition();
            qc.setCstId(fundVO.getCstId());
            qc.setPaySchId(paySchMVO.getId());
            if (null != flowStartTm) {
                qc.setAcceptActualDate(DateUtils.formatDate(flowStartTm, DateUtils.YYYY_MM_DD));
            }

            //查询待分解支付表+罚息
            List<PrjPrdPaySchDVO> voList = this.capFundService.searchPaySchDList(qc);
            
            if(PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_BF.equals(paySchMVO.getPaySchTypCd()) || PrjPrdPaySchMConstant.PAY_SCH_TYP_CD_SH.equals(paySchMVO.getPaySchTypCd())){
            	List<PrjPrdPaySchDVO> list = this.capFundService.searchWSFeeList(paySchMVO.getId());
            	if(null == voList){
            		voList = new ArrayList<>();
            	}
            	if(CollectionUtils.isNotEmpty(list)){
            		voList.addAll(0,list);
            	}
            }
            if (CollectionUtils.isNotEmpty(voList)) {
                //Long amount = 0L;//应收金额
                /*for (PrjPrdPaySchDVO vo : voList) {
                    //amount += vo.getFeeAmt().longValue();
                    if(StringUtils.isNotBlank(vo.getCapFlow())&&CapitalConstant.CODE_CAP_FLOW_2.equals(vo.getCapFlow())){//支出为负
                        vo.setFeeAmt(-vo.getFeeAmt());
                        vo.setArAmt(-vo.getArAmt());
                        if(StringUtils.isNotEmpty(vo.getPaidUpAmt())){
                            vo.setPaidUpAmt(-vo.getPaidUpAmt());
                        }
                    }
                }*/
                //mav.addObject("amount",DecimalUtils.convertFenToYuan(amount));//应收金额
                mav.addObject("paySchList", JSON.toJSONString(voList));
            }

            //结清时间
            PrjPrdDtlQueryCondition dtlQueryCondition = new PrjPrdDtlQueryCondition();
            dtlQueryCondition.setPaySchId(paySchMVO.getId());
            List<PrjPrdDtlVO> prdDtlVOList = this.prjPrdDtlService.selectList(dtlQueryCondition);
            if (CollectionUtils.isNotEmpty(prdDtlVOList)) {
                PrjPrdDtlVO prjPrdDtlVO = prdDtlVOList.get(0);
                if (null != prjPrdDtlVO.getStlDt()) {
                    mav.addObject("stlDt", DateUtils.formatDateToString(prjPrdDtlVO.getStlDt(), DateUtils.YYYY_MM_DD));
                }
                mav.addObject("prjPrdDtlId", prjPrdDtlVO.getId());
            }
        } else if (CapitalConstant.CODE_BIZ_TYP_CD_4.equals(bizTyp)) {//续保，保险保证金查看
            mav.setViewName("capital/capFund/capFstFundModify");
            //查询保单信息
            GetInsPlcBscInfoRequest getRequest = new GetInsPlcBscInfoRequest();
            getRequest.setId(Long.parseLong(dataId));
            ResponseData<InsPlcBscInfoDTO> responseData = this.insPlcBscInfoService.selectById(getRequest);
            InsPlcBscInfoVO plcBscInfoVO = new InsPlcBscInfoVO();
            if (null != responseData && ResponseData.SUCCESS_CODE.equals(responseData.getCode()) && null != responseData.getData()){
                InsPlcBscInfoDTO dto = responseData.getData();
                BeanUtils.copyProperties(dto,plcBscInfoVO);
            }

            /*String handWayCd = plcBscInfoVO.getHandleWayCd();
            if(StringUtils.isNotBlank(handWayCd)){
                Map<String, String> handWayCdMap = this.sysDictionaryApiService.searchGroupToMap(CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd(), InsuranceConstant.CODE_FEE_HANDLE_WAY_CD);
                if(CollectionUtils.isMapNotEmpty(handWayCdMap)){
                    if(handWayCdMap.containsKey(handWayCd)){
                        mav.addObject("handWayCdNm",handWayCdMap.get(handWayCd));
                        mav.addObject("bizTyp",bizTyp);
                    }
                }
            }*/
            //查询支付表保险保证金
            PrjPrdPaySchDQueryCondition prjPrdPaySchDQueryCondition = new PrjPrdPaySchDQueryCondition();
            prjPrdPaySchDQueryCondition.setPaySchId(plcBscInfoVO.getPaySchId());
            prjPrdPaySchDQueryCondition.setFeeTypCd(InsuranceConstant.CODE_FEE_TYP_CD_11);//保险保证金
            List<PrjPrdPaySchDVO> dtlList = prjPrdPaySchDService.searchList(prjPrdPaySchDQueryCondition);
            if (CollectionUtils.isNotEmpty(dtlList)) {
                PrjPrdPaySchDVO paySchDVO = dtlList.get(0);
                //查询保险保证金的处理方式
                CapFeeOutLogQueryCondition logQueryCondition = new CapFeeOutLogQueryCondition();
                logQueryCondition.setPaySchId(plcBscInfoVO.getPaySchId());
                logQueryCondition.setPaySchDId(paySchDVO.getId());
                logQueryCondition.setFeeTypCd(InsuranceConstant.CODE_FEE_TYP_CD_11);
                List<CapFeeOutLogVO> logList = this.capFeeOutLogService.searchList(logQueryCondition);
                if (CollectionUtils.isNotEmpty(logList)) {
                    CapFeeOutLogVO logVO = logList.get(0);
                    mav.addObject("handWayCdNm", logVO.getHandleWayCdNm());
                }
            }
            mav.addObject("bizTyp",bizTyp);
            //查询关联的资金信息
            CapFundQueryCondition fundQueryCondition = new CapFundQueryCondition();
            fundQueryCondition.setRelationPayId(Long.valueOf(dataId));//关联ID
            List<CapFundVO> fundList = this.capFundService.searchList(fundQueryCondition);
            if (CollectionUtils.isNotEmpty(fundList) && fundList.size() > 0) {
                fundVO = fundList.get(0);
                fundVO.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());//认款人ID
                fundVO.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());//认款人名称
                fundVO.setIdentifyTime(new Date());//认款时间 add时会修改
                //默认财务收款账户、账号
                fundVO.setAcceptName(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_NM);//收款账户
                fundVO.setAcceptCode(InsuranceConstant.CODE_FC_ACCEPT_ACCOUNT_CD);//收款账号
                mav.addObject("amount", DecimalUtils.convertFenToYuan(fundVO.getAmount()));
            }

            //查询待分解支付表+罚息
            CapFundQueryCondition qc = new CapFundQueryCondition();
            qc.setPaySchId(plcBscInfoVO.getPaySchId());
            if(fundVO != null){
                qc.setCstId(fundVO.getCstId());
            }
            qc.setAcceptActualDate(DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DD));
            List<PrjPrdPaySchDVO> voList = this.capFundService.searchPaySchDList(qc);
            if (CollectionUtils.isNotEmpty(voList)) {
                mav.addObject("paySchList", JSON.toJSONString(voList));
            }
        }
        if (null != fundVO && fundVO.getAcceptDate() != null) {
            fundVO.setAcceptDates(DateUtils.formatDateToString(fundVO.getAcceptDate(), DateUtils.YYYY_MM_DD));
        }
        if (null != fundVO && fundVO.getAcceptActualDate() != null) {
            fundVO.setAcceptActualDates(DateUtils.formatDateToString(fundVO.getAcceptActualDate(), DateUtils.YYYY_MM_DD));
        }
        mav.addObject("capFundVO", fundVO);
        return mav;
    }

    /*************************
     * 到罚息减免页面，流程中附加页面
     *************************/
    @RequestMapping(value = "/reduFineApply.do", method = {RequestMethod.GET})
    public ModelAndView toReductionPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到罚息减免页面").setKeys("toReductionPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capOverdueInfo/capFineReduction");
        String cstId = request.getParameter("cstId");//客户ID
        String vfId = request.getParameter("vfId");//减免罚息业务主键ID
        String ctrlKey = request.getParameter("ctrlKey");//控制键 0：只能选择 1.选择保存 2.选择并修改金额
        mav.addObject("cstId", cstId);
        mav.addObject("vfId", vfId);
        mav.addObject("ctrlKey", ctrlKey);
        if (StringUtils.isNotEmpty(vfId)) {
            CapFundVfLogVO logVO = this.capFundVfLogService.selectById(Long.valueOf(vfId));
            if (null != logVO) {
                mav.addObject("vfAmt", DecimalUtils.convertFenToYuan(logVO.getVfAmt()));
            }
        }
        return mav;
    }

    /*********************
     * 减免罚息申请
     *********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/reduFineApply.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO reduFineApply(HttpServletRequest request, HttpServletResponse response) {
        String id = request.getParameter("id");//逾期罚息ID
        String vfId = request.getParameter("vfId");//减免流程业务主键
        String vfAmt = request.getParameter("vfAmt");//减免金额
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(id)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("减免罚息申请失败，请先选择要减免的罚息信息");
            BaseLogUtils.newLogger("减免罚息申请,罚息参数为空!").setKeys("reduFineApply",CurrentThreadContext.getCurrentUserName()).info();
            return result;
        }

        CapFundVfDtlQueryCondition vfDtlQueryCondition = new CapFundVfDtlQueryCondition();
        vfDtlQueryCondition.setId(Long.valueOf(id));
        vfDtlQueryCondition.setVfUsrId(CurrentThreadContext.getCurrentUserId());
        vfDtlQueryCondition.setVfUsrNm(CurrentThreadContext.getCurrentUserName());
        if (StringUtils.isNotEmpty(vfId)) {
            vfDtlQueryCondition.setVfId(Long.valueOf(vfId));
        }
        if (StringUtils.isNotBlank(vfAmt)) {
            vfDtlQueryCondition.setVfAmt(DecimalUtils.convertYuanToFen(Double.valueOf(vfAmt.trim().replace(",", ""))));
        }
        vfDtlQueryCondition.setBuOrgCd(CurrentThreadContext.getCurrentOrgCd());//当前用户组织架构

        try {
            result = this.capFundVfDtlService.modifyFineReduction(vfDtlQueryCondition);
            BaseLogUtils.newLogger("减免罚息申请返回DATA:" + JSON.toJSONString(result)).setKeys("reduFineApply",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("减免罚息申请失败.DATA:" + JSONObject.toJSONString(vfDtlQueryCondition)).setKeys("reduFineApply",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("减免罚息申请失败,系统错误.DATA:" + JSONObject.toJSONString(vfDtlQueryCondition)).setKeys("reduFineApply",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }

    /*********************
     * 验证分解单是否可以冲红
     *********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/validateFundRevert.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO validateFundRevert(HttpServletRequest request, HttpServletResponse response) {
        String fundId = request.getParameter("fundId");//分解资金ID
        String vfId = request.getParameter("vfId");//核销ID
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(fundId)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("未找到分解的资金信息");
            return result;
        }
        BaseLogUtils.newLogger("验证分解单" + fundId + "-" + vfId + "是否可以冲红").setKeys("validateFundRevert",CurrentThreadContext.getCurrentUserName()).info();
        boolean flag = this.capFundService.validateFundRevert(Long.valueOf(fundId));
        if (!flag) {
            BaseLogUtils.newLogger("分解单不能冲红，" + CapitalConstant.CODE_FUND_VF_FAILED_REASON_5).setKeys("validateFundRevert",CurrentThreadContext.getCurrentUserName()).info();
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(CapitalConstant.CODE_FUND_VF_FAILED_REASON_5);
        }
        return result;
    }


    /*********************
     * 验证资金能不能分解
     *********************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/validateDecomFund.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO validateDecomFund(HttpServletRequest request, HttpServletResponse response) {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        String ids = request.getParameter("ids");//分解资金ID集合
        if (StringUtils.isEmpty(ids)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("未找到验证的资金信息");
            return result;
        }
        List<Long> idsList = new ArrayList<Long>();
        JSONArray idsArray = JSONArray.fromObject(ids);
        for (Object object : idsArray) {
            idsList.add(Long.valueOf(object.toString()));
        }
        BaseLogUtils.newLogger("验证资金能不能分解" + ids).setKeys("validateDecomFund",CurrentThreadContext.getCurrentUserName()).info();
        result = this.capFundService.validateDecomFund(idsList);
        return result;
    }

    /**
     * 获取请求参数
     *
     * @param request 请求
     * @return
     */
    private CapFundVO getRequestParamForCapFund(HttpServletRequest request) throws BaseException {
        //获取参数
        String id = request.getParameter("id");//主键
        String cstId = request.getParameter("cstId");//客户ID
        String cstNm = request.getParameter("cstNm");//null
        String code = request.getParameter("code");//资金编号
        String comeCode = request.getParameter("comeCode");//来款账户
        String comeName = request.getParameter("comeName");//来款人
        String acceptCode = request.getParameter("acceptCode");//收款账户
        String acceptName = request.getParameter("acceptName");//收款人
        String amount = request.getParameter("amount");//收款金额[核销实收金额]
        String availableAmount = request.getParameter("availableAmount");//可用金额
        String usedAmount = request.getParameter("usedAmount");//已用金额
        //String fundStatusCd = request.getParameter("fundStatusCd");//资金状态集合 CAP0004：0.未分解1.分解中2.已分解3.已作废
        String acceptDate = request.getParameter("acceptDate");//资金到账日期
        String acceptActualDate = request.getParameter("acceptActualDate");//实际到账日期
        String docketRem = request.getParameter("docketRem");//摘要/备注
        String identifyOperator = request.getParameter("identifyOperator");//认款操作人
        String identifyTime = request.getParameter("identifyTime");//认款操作时间
        String identifyOperatorNm = request.getParameter("identifyOperatorNm");//认款操作人名称
        String fundSourcesCd = request.getParameter("fundSourcesCd");//资金来源CAP0002：0-正常来款 1- 保证金转入 2-保险保证金转入 3-保险首期款转入 4-保险退还客户 5- 扣除保险保证金 6-风险保证金转入
        String fundInputCd = request.getParameter("fundInputCd");//资金录入方式 1.手工录入 2.批量导入3.代扣导入4.APP录入
        String fundBelongOrgCd = request.getParameter("fundBelongOrgCd");//所属事业部组织架构？
        String bankCardNo = request.getParameter("bankCardNo");//代扣账号
        String fundTypCd = request.getParameter("fundTypCd");//资金种类(CAP0014) 0.重卡资金 1.保险租金
        //String certificateCd = request.getParameter("certificateCd");//凭证种类-数据字典
        //String certificateCode = request.getParameter("certificateCode");//凭证号码
        String businessCode = request.getParameter("businessCode");//业务编号
        //String borrowingLogoCd = request.getParameter("borrowingLogoCd");//借贷标志-数据字典
        //String moneyType = request.getParameter("moneyType");//币种-数据字典
        //String expStatusCd = request.getParameter("expStatusCd");//导出状态-数据字典：0-未导出 1-已导出
        String relationPayId = request.getParameter("relationPayId");//关联付款ID
        String version = request.getParameter("version");//版本
        String capTypCd = request.getParameter("capTypCd"); //资金类型
        String isAutoCharge = request.getParameter("isAutoCharge"); //是否自动划扣(1.是 0.否)

        //验证参数并赋值
        CapFundVO entity = new CapFundVO();
        if (StringUtils.isNotEmpty(cstId)) {
            entity.setCstId(Long.valueOf(cstId));//客户ID
        }
        Long fundAmt = 0l;
        if (StringUtils.isNotBlank(amount)) {
            if (!StringUtils.isUnsignedNumeric(amount)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写正确的来款金额.");
            }
            Double amt = Double.valueOf(amount);
            fundAmt = DecimalUtils.convertYuanToFen(amt);
        } else {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写来款金额.");
        }
        if (StringUtils.isNotBlank(acceptDate)) {
            entity.setAcceptDate(DateUtils.formatStringToDate(acceptDate, DateUtils.YYYY_MM_DD));//资金到账日期
        } else {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写到账时间.");
        }
        if (StringUtils.isNotBlank(acceptActualDate)) {
            entity.setAcceptActualDate(DateUtils.formatStringToDate(acceptActualDate, DateUtils.YYYY_MM_DD));//实际到账日期
        } else {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请填写实际到账时间.");
        }
        entity.setAmount(fundAmt);//收款金额[核销实收金额]
        if (StringUtils.isNotBlank(id)) {
            if(StringUtils.isNotEmpty(availableAmount)){
                entity.setAvailableAmount(Long.valueOf(availableAmount));//可用金额
            }
            if(StringUtils.isNotEmpty(usedAmount)){
                entity.setUsedAmount(Long.valueOf(usedAmount));//已用金额
            }
        }else{
            entity.setAvailableAmount(fundAmt);//可用金额
            entity.setUsedAmount(0L);//已用金额
        }
        entity.setCstNm(cstNm);//客户名称
        entity.setCode(code);//资金编号
        entity.setComeCode(comeCode);//来款账户
        entity.setComeName(comeName);//来款人
        entity.setAcceptCode(acceptCode);//收款账户
        entity.setAcceptName(acceptName);//收款人

        entity.setDocketRem(docketRem);//摘要
        if (StringUtils.isNotEmpty(isAutoCharge)) {
            entity.setIsAutoCharge(Integer.parseInt(isAutoCharge));//是否自动划扣(1.是 0.否)
        }
        if (StringUtils.isNotEmpty(identifyOperator)) {
            entity.setIdentifyOperator(Long.valueOf(identifyOperator));//认款操作人
        }
        if (StringUtils.isNotBlank(identifyTime)) {
            entity.setIdentifyTime(DateUtils.formatStringToDate(identifyTime, DateUtils.YYYY_MM_DDHHMMSS));//认款操作时间
        }
        entity.setIdentifyOperatorNm(identifyOperatorNm);//认款操作人名称
        if(StringUtils.isNotBlank(fundSourcesCd)){
            entity.setFundSourcesCd(fundSourcesCd);//资金来源CAP0002：0-正常来款 1- 保证金转入 2-保险保证金转入 3-保险首期款转入 4-保险退还客户 5- 扣除保险保证金 6-风险保证金转入
        }else{
            entity.setFundSourcesCd("0");//资金来源CAP0002：0-正常来款 1- 保证金转入 2-保险保证金转入 3-保险首期款转入 4-保险退还客户 5- 扣除保险保证金 6-风险保证金转入
        }
        entity.setFundInputCd(fundInputCd);//资金录入方式 1.手工录入 2.批量导入3.代扣导入4.APP录入
        entity.setFundBelongOrgCd(fundBelongOrgCd);//所属事业部组织架构？
        entity.setBankCardNo(bankCardNo);//代扣账号
        entity.setFundTypCd(fundTypCd);//资金种类(CAP0014) 0.重卡资金 1.保险租金
        //entity.setCertificateCd(certificateCd);//凭证种类-数据字典
        //entity.setCertificateCode(certificateCode);//凭证号码
        entity.setBusinessCode(businessCode);//业务编号
        //entity.setBorrowingLogoCd(borrowingLogoCd);//借贷标志-数据字典
        //entity.setMoneyType(moneyType);//币种-数据字典
        //entity.setExpStatusCd(expStatusCd);//导出状态-数据字典：0-未导出 1-已导出
        if (StringUtils.isNotEmpty(relationPayId)) {
            entity.setRelationPayId(Long.valueOf(relationPayId));//关联付款ID
        }
        if (StringUtils.isNotEmpty(version)) {
            entity.setVersion(Long.valueOf(version));
        }
        if (StringUtils.isNotEmpty(capTypCd)) {
            entity.setCapTypCd(capTypCd);
        }

        Date tm = new Date();
        if (StringUtils.isNotBlank(id)) {
            entity.setId(Long.valueOf(id));
            entity.setMdfTm(tm);
            entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            entity.setFundInputCd(null);
            entity.setFundSourcesCd(null);
        } else {
            entity.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//资金状态集合 CAP0004：0.未分解1.分解中2.已分解3.已作废
            entity.setCrtTm(tm);
            entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
        }

        return entity;
    }


    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportFundList.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportComFundList(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        CapFundExportCondition qc = new CapFundExportCondition();
        String acceptDateMin = request.getParameter("acceptDateMin");
        String acceptDateMax = request.getParameter("acceptDateMax");
        String acceptActualDateMin = request.getParameter("acceptActualDateMin");
        String acceptActualDateMax = request.getParameter("acceptActualDateMax");
        String fundStatusCD = request.getParameter("fundStatusCD");//资金状态
        String identifyOperator = request.getParameter("identifyOperator");//认款人
        String identifyOperatorNm = request.getParameter("identifyOperatorNm");//认款人名称
        String amount = request.getParameter("amount");
        String comeNameAlias = request.getParameter("comeNameAlias");//来款户名
        String comeCodeAlias = request.getParameter("comeCodeAlias");//来款账号
        String acceptCode = request.getParameter("acceptCode");//收款账号
        String capTypCd = request.getParameter("capTypCd"); //资金类型
        String type =request.getParameter("type");//操作类型 1.待认款 2.已分解 3.冻结
        if (StringUtils.isNotEmpty(acceptDateMin)) {
            qc.setAcceptDateMin(acceptDateMin);
        }
        if (StringUtils.isNotEmpty(acceptDateMax)) {
            qc.setAcceptDateMax(acceptDateMax);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMin)) {
            qc.setAcceptActualDateMin(acceptActualDateMin);
        }
        if (StringUtils.isNotEmpty(acceptActualDateMax)) {
            qc.setAcceptActualDateMax(acceptActualDateMax);
        }
        if (StringUtils.isNotBlank(fundStatusCD)) {
            qc.setFundStatusCd(fundStatusCD);
        }
        if (StringUtils.isNotEmpty(identifyOperator)) {
            qc.setIdentifyOperator(Long.parseLong(identifyOperator));
        }
        if (StringUtils.isNotBlank(amount)) {
            qc.setAmount(DecimalUtils.convertYuanToFen(Double.parseDouble(amount)));
        }
        if (StringUtils.isNotBlank(identifyOperatorNm)) {
            qc.setIdentifyOperatorNm(identifyOperatorNm);
        }
        if (StringUtils.isNotBlank(comeNameAlias)) {
            qc.setComeNameAlias(comeNameAlias.trim());
        }
        if (StringUtils.isNotBlank(comeCodeAlias)) {
            qc.setComeCodeAlias(comeCodeAlias);
        }
        if (StringUtils.isNotBlank(acceptCode)) {
            qc.setAcceptCode(acceptCode);
        }
        if(StringUtils.isNotBlank(capTypCd)){
            qc.setCapTypCd(capTypCd);
        }
        if(StringUtils.isNotBlank(type)){
            if ("1".equals(type)) {//待分解资金列表
                List<String> fundStatusList = new ArrayList<>();
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//0.未分解
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_1);//1.分解中
                qc.setFundStatusCdList(fundStatusList);//资金状态集合 CAP0004：0.未分解1.分解中2.已分解3.已作废
                qc.setSortName("crtTm");//按照创建日期排序
                qc.setSortOrder("desc");
            } else if ("2".equals(type)) {//已分解资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_2);//2.已分解
                qc.setSortName("mdfTm");//按照修改日期排序
                qc.setSortOrder("desc");
            } else if("3".endsWith(type)){ // 冻结资金列表
                List<String> fundStatusList = new ArrayList<>();
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_9); //9.已冻结
                fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_6);//6.已转出
                qc.setFundStatusCdList(fundStatusList);
            }else {//作废资金列表
                qc.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_3);//3.已作废
            }
        }

        BaseLogUtils.newLogger("导出资金列表.DATA:" + JSONObject.toJSONString(qc)).setKeys("initCapFundList",CurrentThreadContext.getCurrentUserName()).info();
        return this.capFundService.exportFundList(qc);
    }


    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/modifyStlDt.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO modifyStlDt(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String prjPrdDtlId = request.getParameter("prjPrdDtlId");//项目产品明细ID
        String stlDt = request.getParameter("stlDt");//结清时间
        if(StringUtils.isEmpty(prjPrdDtlId)||StringUtils.isBlank(stlDt)){
            BaseLogUtils.newLogger("修改项目产品明细结清时间异常，请求参数不完整").setKeys("modifyStlDt",CurrentThreadContext.getCurrentUserName()).info();
            return new DataResultVO(BaseConstant.IS_YESNO_NO,"保存失败");
        }
        BaseLogUtils.newLogger("修改项目产品明细结清时间开始" + prjPrdDtlId).setKeys("modifyStlDt",CurrentThreadContext.getCurrentUserName()).info();
        DataResultVO result = this.capFundService.modifyStlDt(Long.valueOf(prjPrdDtlId),stlDt);
        BaseLogUtils.newLogger("修改项目产品明细结清时间完成" + prjPrdDtlId + ";" + JSON.toJSONString(result)).setKeys("modifyStlDt",CurrentThreadContext.getCurrentUserName()).info();
        return result;
    }
    /**
     * 到还款情况(财务)页面
     */
    @RequestMapping(value = "/toRepaymentSituation.do", method = {RequestMethod.GET})
    public ModelAndView toRepaymentSituation(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载还款情况列表页面.").setKeys("toRepaymentSituation",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView view = new ModelAndView("capital/capFund/repaymentSituationPage");
        	//项目类型
      		List<KeyValueVO> projectTypeList = this.prjBscInfoService.getPrjTypCdALLKV();
      		//业务类型
      		List<KeyValueVO> bizTypeList = this.prjBscInfoService.getBizTypeList();
      		// 事业部
      		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
      		//业务类型
      		List<KeyValueVO> prdStsCdList = this.prjBscInfoService.getPrdStsCdList();
      		view.addObject("orgListList", orgList);
    		view.addObject("projectTypeList", projectTypeList);
    		view.addObject("bizTypeList", bizTypeList);
       		view.addObject("prdStsCdList", prdStsCdList);
    		view.addObject("currentBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());
        return view;
    }
    /**
     * 到还款详细页面
     */
    @RequestMapping(value = "/toRepaymentSituationDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toPrjPrdPaySchMDetailPage(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载toRepaymentSituationDetailPage 页面").setKeys("toPrjPrdPaySchMDetailPage",CurrentThreadContext.getCurrentUserName()).info();
        ModelAndView mav = new ModelAndView("capital/capFund/repaymentSituationDetailPage");
        String id = request.getParameter("id");// 支付表ID
        PrjPrdPaySchMVO vo = null;
        CapOverdueInfoVO cap = null;
        double totalPardUpAmt = 0d;
        double totalRntAmt = 0d;
        List<PrjPrdPaySchDVO> payList = new ArrayList<PrjPrdPaySchDVO>();
        ListPageVO<PrjPrdPaySchDVO> listPage = null;


        if (StringUtils.isNotBlank(id)) {
            vo = this.prjPrdPaySchMService.selectPrjPrdPaySchMAndDetailById(Long.valueOf(id));
            CapOverdueInfoQueryCondition capQc = new CapOverdueInfoQueryCondition();
            capQc.setIsDel(BaseConstant.IS_YESNO_NO);
            capQc.setPaySchId(Long.valueOf(id));
            capQc.setOverdueStatusCd(BaseConstant.IS_YESNO_NO + "");
            capQc.setCreateDate(new Date());
            List<CapOverdueInfoVO> capList = capOverdueInfoService.searchOvdDtlList(capQc);
            if (CollectionUtils.isNotEmpty(vo.getPrjPrdPaySchDList())) {
                List<PrjPrdPaySchDVO> list = vo.getPrjPrdPaySchDList();
                List<PrjPrdPaySchDVO> totalList = new ArrayList<PrjPrdPaySchDVO>();
                for (PrjPrdPaySchDVO detail : vo.getFeeDetailList()) {
                    if (detail.getCntWayCd().equals(PrjQuatPrpsConstant.CODE_PRJ_QUAT_CNT_WAY_DOWNPAY)) {
                        totalList.add(detail);
                    }
                    if (null != detail.getFeeTypCd() && (detail.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.CODE_FEE_WAY_TYPE_RICK_DEP) || detail.getFeeTypCd().equals(PrjQuatPrpsFeeConstant.FEE_TYP_CD_104))) {
                        totalList.add(detail);
                    }
                }
                totalList.addAll(list);
                for (PrjPrdPaySchDVO prjPrdPaySchDVO : totalList) {
                    if (null == prjPrdPaySchDVO.getCntWayCd()) {
                        if (null != prjPrdPaySchDVO.getFeeAmt()) {
                            prjPrdPaySchDVO.setFeeAmt(DecimalUtils.convertFenToYuan(prjPrdPaySchDVO.getFeeAmt().longValue()));
                        }
                    }
                    if (prjPrdPaySchDVO.getPayPd() == PrjQuatPrpsConstant.CODE_PRJ_PRD_FEE_PD.intValue() || prjPrdPaySchDVO.getFeeTypCd().equals(PrjQuatPrpsConstant.CODE_FEE_WAY_TYPE_RNT_PRICE)) {
                        payList.add(prjPrdPaySchDVO);
                        //计算合计信息
                        totalPardUpAmt = DecimalUtils.add(totalPardUpAmt, prjPrdPaySchDVO.getPaidUpAmt() == null ? 0 : prjPrdPaySchDVO.getPaidUpAmt());
                    }
                }
                totalRntAmt = DecimalUtils.add(vo.getTotalRntAmt(), vo.getFirstPayAmt());
            }

            listPage = new ListPageVO<PrjPrdPaySchDVO>(payList, payList.size());
            if (CollectionUtils.isNotEmpty(capList)) {
                capList.get(0);
            }

            // 罚息、损益
            getAmt(id, mav);
        }

        mav.addObject("listPage", JSON.toJSONString(listPage));
        mav.addObject("cap", cap);
        mav.addObject("totalPardUpAmt", totalPardUpAmt);
        mav.addObject("totalRntAmt", totalRntAmt);
        mav.addObject("id", id);

        return mav;
    }

    /**
     * 计算罚息和损益
     * @param paySchId 支付表id(PRJ_PRD_PAY_SCH_M表)
     * @param mav ModelAndView对象
     */
    private void getAmt(String paySchId, ModelAndView mav) {
        String totalPenaltyAmt = "0";// 总罚息金额
        String totalRealPayPenaltyAmt = "0";// 实付罚息金额
        String s03Amt = "0";// 本金损益
        String s02Amt = "0";// 利息损益
        String towingFeeAmt = "0";// 拖车相关费用损益
        String badDebtLossAmt = "0";// 确认坏账损失

        PrjPrdDtlQueryCondition dtlQueryCondition = new PrjPrdDtlQueryCondition();
        dtlQueryCondition.setPaySchId(Long.valueOf(paySchId));
        List<PrjPrdDtlVO> dtlVOList = prjPrdDtlService.selectList(dtlQueryCondition);

        PrjPrdDtlVO dtlVO = new PrjPrdDtlVO();
        if (null != dtlVOList && dtlVOList.size() > 0) {
            dtlVO = dtlVOList.get(0);
        }
        if (null != dtlVO && null != dtlVO.getPrdStsCd()) {
            String prdStsCd = dtlVO.getPrdStsCd();
            // S010301-已正常结清，S010401-已提前结清, S010501-已强制结清, S0106020201-已赎回结清, S01060203010101-优车已处置
            if (prdStsCd.equals("S010301") || prdStsCd.equals("S010401") || prdStsCd.equals("S010501")
                    || prdStsCd.equals("S0106020201") || "S01060203010101".equals(prdStsCd)) {
//                CapOverdueInfoVO infoVO = this.capOverdueInfoService.getAmt(Long.valueOf(paySchId));
                ProfitAndLossVO infoVO = this.profitAndLossService.getAmt(Long.valueOf(paySchId));
                BaseLogUtils.newLogger("还款情况(财务)，罚息&损益：" + JSON.toJSONString(infoVO)).setKeys("toPrjPrdPaySchMDetailPage",CurrentThreadContext.getCurrentUserName()).info();
                if (null != infoVO) {
                    Long temp = 0L;
                    if (null != infoVO.getTotalPenaltyAmt() && infoVO.getTotalPenaltyAmt() > 0) {
                        totalPenaltyAmt = "" + DecimalUtils.convertFenToYuan(infoVO.getTotalPenaltyAmt());
                    }
                    if (null != infoVO.getTotalRealPayPenaltyAmt() && infoVO.getTotalRealPayPenaltyAmt() > 0){
                        totalRealPayPenaltyAmt = "" + DecimalUtils.convertFenToYuan(infoVO.getTotalRealPayPenaltyAmt());
                        temp += infoVO.getTotalRealPayPenaltyAmt();
                    }
                    if (null != infoVO.getS02Amt() && infoVO.getS02Amt() > 0) {
                        s02Amt = "" + DecimalUtils.convertFenToYuan(0-infoVO.getS02Amt());
                    }
                    if (null != infoVO.getS03Amt() && infoVO.getS03Amt() > 0) {
                        s03Amt = "" + DecimalUtils.convertFenToYuan(0-infoVO.getS03Amt());
                        temp += (0-infoVO.getS03Amt());
                    }
                    if (null != infoVO.getTowingFeeAmt() && infoVO.getTowingFeeAmt() > 0) {
                        towingFeeAmt = "" + DecimalUtils.convertFenToYuan(0-infoVO.getTowingFeeAmt());
                        temp += (0-infoVO.getTowingFeeAmt());
                    }

                    badDebtLossAmt = "" + DecimalUtils.convertFenToYuan(temp);
                }
            }
        }

        mav.addObject("totalPenaltyAmt", totalPenaltyAmt);// 总罚息金额
        mav.addObject("totalRealPayPenaltyAmt", totalRealPayPenaltyAmt);// 实付罚息金额
        mav.addObject("s03Amt",  s03Amt);// 本金损益
        mav.addObject("s02Amt", s02Amt);// 利息损益
        mav.addObject("towingFeeAmt", towingFeeAmt);// 拖车相关费用损益
        mav.addObject("badDebtLossAmt", badDebtLossAmt);// 确认坏账损失

        BaseLogUtils.newLogger("还款情况(财务)，罚息&损益(toPage)："+totalPenaltyAmt
                +"|"+ totalRealPayPenaltyAmt +"|"+s03Amt+"|"+s02Amt+"|"+towingFeeAmt+"|"+badDebtLossAmt).setKeys("toPrjPrdPaySchMDetailPage",CurrentThreadContext.getCurrentUserName()).info();
    }

    /*************
     * 修改 资金类型
     *************/
    @RequestMapping(value = "/modifyFundType.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object modifyFundType(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        CapFundVO entity = new CapFundVO();
        try {
            String id = request.getParameter("id");
            String capTypCd = request.getParameter("value");

            if (StringUtils.isEmpty(id)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("修改CapFund信息,主键参数为空！.").setKeys("modifyFundType",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            entity.setId(Long.valueOf(id));

            if(StringUtils.isNotBlank(capTypCd)){
            	entity.setCapTypCd(capTypCd);
            	entity.setMdfTm(DateUtils.formatDate(new Date(), DateUtils.YYYY_MM_DDHHMMSS) );
                entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());
            }
            boolean success = this.capFundService.modify(entity);
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundType",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            result.setData(entity.getId());
            BaseLogUtils.newLogger("修改CapFund数据成功.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundType",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundType",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundType",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }



    /*************
     * 冻结资金
     *************/
    @RequestMapping(value = "/modifyFundFreeze.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object modifyFundFreeze(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        CapFundVO entity=null;
        try {
            String ids = request.getParameter("ids");
            if (StringUtils.isEmpty(ids)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("修改CapFund信息,主键参数为空").setKeys("modifyFundFreeze",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }

            List<CapFundVO> idsList = new ArrayList<CapFundVO>();
            JSONArray idsArray = JSONArray.fromObject(ids);
            for (Object object : idsArray) {
            	entity = new CapFundVO();
            	entity.setId(Long.valueOf(object.toString()));
            	entity.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_9);//已冻结
            	entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());//用户id
            	idsList.add(entity);
            }
           //资金冻结
           boolean success = this.capFundService.ModifyListFundCstInfo(idsList);

            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundFreeze",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            result.setData(entity.getId());
            BaseLogUtils.newLogger("修改CapFund数据成功.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundFreeze",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundFreeze",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundFreeze",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }


    /*************
     * 资金转出
     *************/
    @RequestMapping(value = "/modifyFundOut.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object modifyFundOut(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_UPDATE_SUCC);
        CapFundVO entity=null;
        try {
            String ids = request.getParameter("ids");
            if (StringUtils.isEmpty(ids)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
                BaseLogUtils.newLogger("修改CapFund信息,主键参数为空").setKeys("modifyFundOut",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }

            List<CapFundVO> idsList = new ArrayList<CapFundVO>();
            JSONArray idsArray = JSONArray.fromObject(ids);
            for (Object object : idsArray) {
            	entity = new CapFundVO();
            	entity.setId(Long.valueOf(object.toString()));
            	entity.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_6);//已转出
            	entity.setMdfUsrId(CurrentThreadContext.getCurrentUserId());//用户id
            	idsList.add(entity);
            }
           //资金转出
           boolean success = this.capFundService.ModifyListFundCstInfo(idsList);

            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_UPDATE_FAIL);
                BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity)).setKeys("modifyFundOut",CurrentThreadContext.getCurrentUserName()).info();
                return result;
            }
            result.setData(entity.getId());
            BaseLogUtils.newLogger("修改CapFund数据成功.DATA" + JSONObject.toJSONString(entity)).setKeys("modifyFundOut",CurrentThreadContext.getCurrentUserName()).info();
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败.DATA:" + JSONObject.toJSONString(entity) ).setKeys("modifyFundOut",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR + ex.getMessage());
            BaseLogUtils.newLogger("修改CapFund数据失败,系统错误.DATA:" + JSONObject.toJSONString(entity) ).setKeys("modifyFundOut",CurrentThreadContext.getCurrentUserName()).setThrowable(ex).error(LogExceptionEnum.API_CODE_0102);
        }
        return result;
    }



	public List<KeyValueVO> toFundConfirmByListPage(HttpServletRequest request, HttpServletResponse response) {
		/**下拉数据*/
       List<KeyValueVO> searchFundTypeCdList = this.capFundService.searchFundTypeCdList();
       if(CollectionUtils.isNotEmpty(searchFundTypeCdList)){
           BaseLogUtils.newLogger("初始化资金类型成功").setKeys("toFundConfirmByListPage",CurrentThreadContext.getCurrentUserName()).info();
    	   return searchFundTypeCdList;
       }else{
           BaseLogUtils.newLogger("初始化资金类型有误").setKeys("toFundConfirmByListPage",CurrentThreadContext.getCurrentUserName()).info();
       return searchFundTypeCdList;
       }
	}

	/**
	 * 处理资金分解时间问题
	 * @param list
	 */
	private void toFundDecomposeTimeList(List<CapFundVO> list) {
		List<Long>   arraylist=new  ArrayList<Long>();
		if (CollectionUtils.isNotEmpty(list)) {
		for (CapFundVO capFundVO : list) {
			  arraylist.add(capFundVO.getId());//列表中的资金id
	       }
		List<CapFundVfLogRVO> searchVList = this.capFundVfLogRService.searchVList(arraylist);//去关联表中查询所有的资金id对应的核销id
		Map<Long, Date> fundVHMap = this.capFundVfLogService.searchfundVHList(searchVList, arraylist);//核销详细
		if(CollectionUtils.isMapNotEmpty(fundVHMap)&&CollectionUtils.isNotEmpty(list)){
			for (CapFundVO capFundVO : list) {
				if(fundVHMap.containsKey(capFundVO.getId())){
				capFundVO.setDecomposeTime(fundVHMap.get(capFundVO.getId()));
				}
			}
		}
	}
}
	/**
	 * 处理资金冻结页面中的剩余可转金额问题
	 * @param list
	 */
	private void toFundSurplusOutAmtList(List<CapFundVO> list) {
		List<Long>   arraylist=null;
		if (CollectionUtils.isNotEmpty(list)) {
			  arraylist=new  ArrayList<Long>();
		for (CapFundVO capFundVO : list) {
			  arraylist.add(capFundVO.getId());//列表中的资金id
	       }
		List<CapFundOutLogVO> searchVList = this.ICapFundOutLogService.searchVList(arraylist);//去转出记录表中直接查  （无中间表）
		Map<Long, Long> searchMapList = this.capFundService.searchfundVHList(searchVList, list);//具体计算实现
		if(CollectionUtils.isMapNotEmpty(searchMapList)){
			for (CapFundVO capFundVO : list) {
				if(searchMapList.containsKey(capFundVO.getId())){
				capFundVO.setSurpluOutAmt(searchMapList.get(capFundVO.getId()));
				}
			}
		}
	}
}
	/**
	 * 资金转出记录页面
	 * @param request
	 * @param response
	 * @return
	 */
    @RequestMapping(value = "/toFundConfirmFrozen.do", method = {RequestMethod.GET})
    public ModelAndView toFundConfirmFrozen(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("加载到资金转出记录页面").setKeys("toFundConfirmFrozen",CurrentThreadContext.getCurrentUserName()).info();
        String fundId = request.getParameter("ids");
        String fundAmt = request.getParameter("fundAmt");
        ModelAndView mav = new ModelAndView("capital/capFund/capFundConfirmFrozenAdd");
        List<KeyValueVO> searchCdList = this.ICapFundOutLogService.searchCdList(CapitalConstant.CODE_CAP_OUT_TYP_CD);
        mav.addObject("FundConfirmFrozenListJSON", JSONArray.fromObject(searchCdList));
        mav.addObject("fundAmt", fundAmt);
        mav.addObject("fundId", fundId);
        return mav;
    }

    /**
     * 选择来款绑定流程
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/toChooseFund.do", method = {RequestMethod.GET})
    public ModelAndView toChooseFund(HttpServletRequest request, HttpServletResponse response){
        BaseLogUtils.newLogger("到选择来款绑定流程页面").setKeys("toChooseFund",CurrentThreadContext.getCurrentUserName()).info();
        String cstId = request.getParameter("cstId");
        String cstNm = request.getParameter("cstNm");
        String relationPayId = request.getParameter("relationPayId");
        String type = request.getParameter("type");
        //业务类型 1.结清 2.添加风险保证金
        String bizTypCd = request.getParameter("bizTypCd");
        if(StringUtils.isEmpty(cstId)||StringUtils.isBlank(cstNm)||StringUtils.isEmpty(relationPayId)){
            BaseLogUtils.newLogger("到选择来款绑定流程页面失败，参数不全").setKeys("toChooseFund",CurrentThreadContext.getCurrentUserName()).info();
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600,"请求参数不完整");
        }
        ModelAndView mav = new ModelAndView("capital/capFund/chooseFund");
        mav.addObject("cstId", cstId);
        mav.addObject("cstNm", cstNm);
        mav.addObject("relationPayId", relationPayId);
        mav.addObject("type",type);
        mav.addObject("bizTypCd",bizTypCd);
        return mav;
    }
    
    /**
     * 同一打款人第16天打来第二笔资金，系统提示有历史资金未使用，不支持新资金认款分解(根据来款人名称和来款卡号进行筛选)
     * @param request
     * @param response
     * @return
     */
	@RequestMapping(value = "/getCapFundForSameAccept.do", method = { RequestMethod.POST})
	@ResponseBody
    public DataResultVO getCapFundForSameAccept(HttpServletRequest request, HttpServletResponse response){
		Long startTm = System.currentTimeMillis();
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "同一打款人第16天打来第二笔资金验证成功！");
		String comeCode = request.getParameter("comeCode");//来款卡号
		String comeName = request.getParameter("comeName");//来款人
		String acceptDate = request.getParameter("acceptDate");//来款日期
		if (StringUtils.isBlank(comeCode)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("来款卡号不能为空！");
            BaseLogUtils.newLogger("来款卡号不能为空！").setKeys("getCapFundForSameAccept",CurrentThreadContext.getCurrentUserName()).info();
			return result;
		}
		if (StringUtils.isBlank(comeName)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("来款人不能为空！");
            BaseLogUtils.newLogger("来款人不能为空！").setKeys("getCapFundForSameAccept",CurrentThreadContext.getCurrentUserName()).info();
			return result;
		}
		if (StringUtils.isBlank(acceptDate)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("来款时间不能为空！");
            BaseLogUtils.newLogger("来款时间不能为空！").setKeys("getCapFundForSameAccept",CurrentThreadContext.getCurrentUserName()).info();
			return result;
		}
		try {
			Date acceptTm = new Date();
			acceptTm.setTime(Long.valueOf(acceptDate));
			//根据来款人名称和来款卡号进行筛选资金信息
			CapFundQueryCondition condition = new CapFundQueryCondition();
			condition.setComeCode(comeCode);
			condition.setComeName(comeName);
			List<String> fundStatusCdList = new ArrayList<String>();
			fundStatusCdList.add("0");
			fundStatusCdList.add("1");
			condition.setFundStatusCdList(fundStatusCdList);
			List<CapFundVO> capFundVOList = this.capFundService.searchList(condition);
			if (CollectionUtils.isNotEmpty(capFundVOList)) {
				for (CapFundVO capFundVO : capFundVOList) {
					Date acceptDateSun = capFundVO.getAcceptDate();
					if (acceptDateSun != null) {
						Long bwDate= DateUtils.getDaysBetweenTwoDates(acceptDateSun, acceptTm);
						if (bwDate.compareTo(15l) == 1) {
							result.setSuccess(BaseConstant.IS_YESNO_NO);
							result.setInfo("有历史资金未使用，不支持新资金认款分解");
							result.setData(capFundVO);
							return result;
						}
					}
				}
			} else {
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				result.setInfo("未找到相关来款记录");
                BaseLogUtils.newLogger("未找到相关来款记录,来款卡号:" + comeCode + "-来款人:" + comeName).setKeys("getCapFundForSameAccept",CurrentThreadContext.getCurrentUserName()).info();
			}
		} catch (BaseException e) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("获取来款记录失败！");
            BaseLogUtils.newLogger("获取来款记录失败！" + comeCode + "-来款人:" + comeName).setKeys("getCapFundForSameAccept",CurrentThreadContext.getCurrentUserName()).info();
		}
		Long endTm = System.currentTimeMillis();
    	return result;
    }
	
	/**
	 * 保险每月还款导入并自动核销
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/insCapFundImportAndAutoVerify.do", method = { RequestMethod.POST})
	@ResponseBody
	public DataResultVO insCapFundImportAndAutoVerify(HttpServletRequest request, HttpServletResponse response) {
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "保险每月还款导入并自动核销 成功！");
		
		String filePath = request.getParameter("filePath");
		if (StringUtils.isBlank(filePath)) {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("请先上传“每月还款明细”文件");
			return result;
		}

        List<InsCapFundVO> list = null;
        File file = new File(PropertiesCacheUtils.getProperty(UploadConstant.UPLOAD_ROOT_PATH) + filePath);
        if (file.exists()) {
            BaseLogUtils.newLogger("保险每月还款导入并自动核销").setKeys("insCapFundImportAndAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
            ImportParams params = new ImportParams();
            params.setTitleRows(0);//标题占用行数
            params.setHeadRows(1);//表头占用行数
            params.setNeedSave(false);//是否保存文件
            list = ExcelImportUtil.importExcel(file, InsCapFundVO.class, params);
            Map<String,InsPayInfoDTO> payNoMap=new HashMap<String,InsPayInfoDTO>();
            if(list.size()>300){
    			result.setSuccess(BaseConstant.IS_YESNO_NO);
    			result.setInfo("最多导入300行来款信息！");
    			return result;
            }
            for(InsCapFundVO insCapFundVo : list) {
            	payNoMap.put(insCapFundVo.getPayNo(), null);
            }
            for(InsCapFundVO insCapFundVo : list) {
        		if(insCapFundVo.getAcceptDate()==null){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的付款日期不能为空！");
        			return result;
        		}
        		if(StringUtils.isEmpty(insCapFundVo.getAcceptCode())){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的收款账号不能为空！");
        			return result;
        		}
        		if(StringUtils.isEmpty(insCapFundVo.getAcceptName())){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的收款账户不能为空！");
        			return result;
        		}
        		if(insCapFundVo.getAmount()==null){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的来款金额不能为空！");
        			return result;
        		}
        		if(StringUtils.isEmpty(insCapFundVo.getComeCode())){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的来款账号不能为空！");
        			return result;
        		}
        		if(StringUtils.isEmpty(insCapFundVo.getComeName())){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的来款户名不能为空！");
        			return result;
        		}
        		if(StringUtils.isEmpty(insCapFundVo.getPayNo())){
          			result.setSuccess(BaseConstant.IS_YESNO_NO);
        			result.setInfo("导入文件中的支付表号不能为空！");
        			return result;
        		}
            	//检查支付表变化是否在保险支付表中存在，若是不存在则弹出信息
            	if(payNoMap.containsKey(insCapFundVo.getPayNo())){
                	InsPayInfoQC qc=new InsPayInfoQC();
                	qc.setPayNo(insCapFundVo.getPayNo());
                	List<InsPayInfoDTO> insDtos=insQueryApiService.searchInsPayInfoList(qc);
                	InsPayInfoDTO insDto=null;
                	if(insDtos!=null&&insDtos.size()>0){
                		insDto=insDtos.get(0);
                	}
                	if(insDto==null||insDto.getPayNo()==null||"".equals(insDto.getPayNo())){
            			result.setSuccess(BaseConstant.IS_YESNO_NO);
            			result.setInfo("文件中的支付表号：" + insCapFundVo.getPayNo()+"，在保险支付表中不存在！请检查文件");
            			return result;
                	}else{

                		if(insDto.getCustomerId()==null||"".equals(insDto.getCustomerId())){
                			result.setSuccess(BaseConstant.IS_YESNO_NO);
                			result.setInfo("保险支付表中的客户号为空，请检查导入保险支付表的数据。");
                			return result;
                		}
                        //查询客户信息
                        CstBscInfoQueryCondition cstBscInfoQueryCondition = new CstBscInfoQueryCondition();
                        List<Long> cstIdList=new ArrayList<Long>();
                        cstIdList.add(insDto.getCustomerId());
                        cstBscInfoQueryCondition.setIds(cstIdList);
                        cstBscInfoQueryCondition.setSysCd(CapitalConstant.SYSCD);
                        cstBscInfoQueryCondition.setOrgCd(CapitalConstant.SYSORG);
                        List<CstBscInfoDTO> cstList = this.customerQueryApiService.searchCstBscInfoList(cstBscInfoQueryCondition);
                		if(cstList==null||cstList.size()==0){
                			result.setSuccess(BaseConstant.IS_YESNO_NO);
                			result.setInfo("保险支付表中的客户号：" + insDto.getCustomerId()+"，在用户表中不存在！导入保险支付表的数据。");
                			return result;
                		}
                        payNoMap.put(insCapFundVo.getPayNo(), insDto);
                	}
            	}

                BaseLogUtils.newLogger("保险每月还款导入并自动核销" + JSON.toJSONString(insCapFundVo)).setKeys("insCapFundImportAndAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
            }
            List<CapFundVO> capFunlist =new ArrayList<CapFundVO>();
            for(InsCapFundVO insCapFundVo : list) {
            	InsPayInfoDTO insDto=payNoMap.get(insCapFundVo.getPayNo());
            	CapFundVO vo=new CapFundVO();
            	vo.setCstId(insDto.getCustomerId());
            	vo.setCstNm(insDto.getCustomerNm());
            	vo.setAcceptCode(insCapFundVo.getAcceptCode());
            	vo.setAcceptName(insCapFundVo.getAcceptName());
            	vo.setComeCode(insCapFundVo.getComeCode());
            	vo.setComeName(insCapFundVo.getComeName());
            	vo.setDocketRem(insCapFundVo.getPayNo());
            	vo.setBusinessCode(insCapFundVo.getPayNo());
            	vo.setAmount(DecimalUtils.convertYuanToFen(insCapFundVo.getAmount()));
            	vo.setAvailableAmount(DecimalUtils.convertYuanToFen(insCapFundVo.getAmount()));
            	vo.setUsedAmount(0L);
            	vo.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_DECO_U);//未分解
            	vo.setFundSourcesCd(CapitalConstant.CODE_CAP_FUND_SRC_C);//正常来款
            	vo.setAcceptActualDate(insCapFundVo.getAcceptDate());//实际到账日期=交易时间
            	vo.setAcceptDate(insCapFundVo.getAcceptDate());
            	vo.setFundInputCd(CapitalConstant.CODE_CAP_FUND_INPUT_CD_2);//资金录入类型：手工批量上传
            	vo.setCrtTm(new Date());
            	vo.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            	vo.setFundTypCd("1");
            	vo.setIdentifyOperator(CurrentThreadContext.getCurrentUserId());
            	vo.setIdentifyOperatorNm(CurrentThreadContext.getCurrentUserName());
            	vo.setIdentifyTime(new Date());
            	capFunlist.add(vo);

            }
            boolean flag = this.capFundService.add(capFunlist);
           

            if (!flag) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
                BaseLogUtils.newLogger("保险资金导入失败.DATA:" + filePath).setKeys("insCapFundImportAndAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
               return result;
            }else{
//              CapFundQueryCondition capFunQc=new CapFundQueryCondition();
//              capFunQc.setCstId(cstId);
//              List<CapFundVO> capFuns=capFundService.searchList(capFunQc);

//              List<Long> idsList=new ArrayList<Long>();
//              for(CapFundVO vo:capFunlist){
//            	  idsList.add(vo.getId());
//              }
//              asdf
//              //资金分解
//              CapFundQueryCondition qc = new CapFundQueryCondition();
//              qc.setIdList(idsList);
//              result = this.capFundService.batchDecomFund(qc);
            }
            
        }
        else {
			result.setSuccess(BaseConstant.IS_YESNO_NO);
			result.setInfo("未找到文件" + filePath);
        }
        result.setSuccess(BaseConstant.IS_YESNO_YES);
        result.setInfo("导入保险来款成功！");
		return result;
	}
	


	/**
	 * 保险自动核销
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/insAutoVerify.do", method = { RequestMethod.POST})
	@ResponseBody
	public DataResultVO insAutoVerify(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.newLogger("来款自动分解开始").setKeys("insAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
		DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, "保险自动核销 成功！");
        //待分解资金ID集合
        String ids = request.getParameter("ids");
        CapFundQueryCondition condition=new CapFundQueryCondition();
        List<Long> idsList = null;
        if (StringUtils.isNotBlank(ids)) {
            String[] idArray = ids.split(",");
            idsList = new ArrayList<>(idArray.length);
            for (String id : idArray) {
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                idsList.add(Long.parseLong(id));
            }
        }
        if (CollectionUtils.isNotEmpty(idsList)) {
        	condition.setIdList(idsList);
        }
        CapFundQueryCondition capFundsQc=new CapFundQueryCondition();
        capFundsQc.setIdList(idsList);
        List<CapFundVO> capFunds= this.capFundService.searchList(capFundsQc);

        String retValue="分解支付表：";
        for(CapFundVO capFundDto:capFunds){
        	String payNo=capFundDto.getBusinessCode();
        	//若等于BX说明是导入进来的数据若等于ZJ说明是核销过的数据，根据摘要查询payno
        	/*if(payNo.startsWith("ZJ")){
              	String docketRem=capFundDto.getDocketRem();
              	String[] strInfo=docketRem.split(",");
              	for(int i=0;i<strInfo.length;i++){
              		String strValue=strInfo[i];
              		if(strValue.contains("BX")){
              			payNo=strValue;
              			break;
              		}
              	}
        	}*/
        	
        	List<String> paynolist = new ArrayList<String>();
			if(StringUtils.isNotEmpty(payNo)&&CapitalConstant.CODE_CAP_FUND_TYP_CD_1.equals(capFundDto.getFundTypCd())){
				paynolist.add(payNo);
			}else{
				result.setSuccess(BaseConstant.IS_YESNO_NO);
				retValue+=capFundDto.getCode()+",不是保险的来款！";
				result.setInfo(retValue);
				return result;
			}
			//调用分解方法
			CapFundQueryCondition capfundqc = new CapFundQueryCondition();
			capfundqc.setPaySchNoList(paynolist);//支付表编号
			capfundqc.setAcceptName(capFundDto.getAcceptName());//收款方名称，支付平台名称
			capfundqc.setAcceptCode(capFundDto.getAcceptCode());//收款方账号，支付平台商户号
			capfundqc.setAcceptDate(capFundDto.getCrtTm());//资金到账时间
			capfundqc.setAmount(capFundDto.getAmount());//支付金额
			capfundqc.setBusinessCode(capFundDto.getCode());//订单id
            capfundqc.setId(capFundDto.getId());//资金id
            BaseLogUtils.newLogger("来款自动分解保险请求参数capfundqc:" + JSONObject.toJSONString(capfundqc)).setKeys("insAutoVerify",CurrentThreadContext.getCurrentUserName()).info();
			DataResultDTO datadto  = capCstPayListService.addFundDecomposeForBx(capfundqc);
            if (null == datadto || "0".equals(datadto.getCode())) {
                retValue=capFundDto.getCode()+"分解失败！错误信息："+datadto.getInfo();
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(retValue);
                return result;
            }
        }
        result.setSuccess(BaseConstant.IS_YESNO_YES);
        result.setInfo("分解成功");
		return result;
	}

    /**
     * 冻结操作
     * @param request
     * @return
     */

    @RequestMapping(value = "/frozenCapital.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO frozenCapital(HttpServletRequest request) {
        DataResultVO result = new DataResultVO();
        try {
            BaseLogUtils.newLogger("来款核销(手动)冻结开始").setKeys("frozenCapital",CurrentThreadContext.getCurrentUserName()).info();
            // 资金ID
            String capFundIdStr = request.getParameter("capFundId");
            if (StringUtils.isBlank(capFundIdStr)) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("冻结操作失败，资金ID不能为空！");
                return result;
            }
            Long capFundId = Long.parseLong(capFundIdStr);
            // 1.修改此笔资金为9-冻结
            CapFundVO vo = new CapFundVO();
            vo.setId(capFundId);
            vo.setFundStatusCd(CapitalConstant.CODE_CAP_FUND_STS_CD_9);
            boolean success = capFundService.modify(vo);
            if (success) {
                // 2.insert进入资金池
                CapFundIntoLogVO entity = new CapFundIntoLogVO();
                entity.setFundId(capFundId);
                entity.setCrtTm(new Date());
                entity.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
                entity.setCrtUsrNm(CurrentThreadContext.getCurrentUserName());
                capFundIntoLogService.add(entity);

                result.setSuccess(BaseConstant.IS_YESNO_YES);
                result.setInfo("冻结操作成功！");
            } else {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("冻结操作失败！");
            }
        } catch (BaseException e) {
            BaseLogUtils.newLogger("来款核销(手动)冻结异常").setKeys("frozenCapital",CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("业务逻辑异常，操作失败！");
        } catch (Exception e) {
            BaseLogUtils.newLogger("来款核销(手动)冻结异常").setKeys("frozenCapital",CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo("系统异常，操作失败！");
        }
        return result;
    }

    @RequestMapping(value = "/queryCapFund.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object queryCapFund(HttpServletRequest request, HttpServletResponse response) {
        String applyLogId = request.getParameter("applyLogId");
        if (StringUtils.isEmpty(applyLogId)) {
            return null;
        }
        InsOfflineRepayLogVO repayLogVO = insOfflineRepayLogService.selectById(Long.parseLong(applyLogId));
        if (Objects.isNull(repayLogVO) || Objects.isNull(repayLogVO.getCrCntNo())) {
            return null;
        }
        McrBillMQC qc = new McrBillMQC();
        qc.setCrCntNo(repayLogVO.getCrCntNo());
        List<McrBillMDTO> mcrBillMDTOList = mcrBillMApiService.searchMcrBillMList(qc);
        if (org.springframework.util.CollectionUtils.isEmpty(mcrBillMDTOList)) {
            return null;
        }
        String currentPage = "1";
        String pageSize = "50";
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }
        if (StringUtils.isNotEmpty(pageSize)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        CapFundQueryCondition condition = new CapFundQueryCondition();
        List<String> fundStatusList = new ArrayList<>();
        fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_0);//0.未分解
        fundStatusList.add(CapitalConstant.CODE_CAP_FUND_STS_CD_1);//1.分解中
        condition.setFundStatusCdList(fundStatusList);
        condition.setCstId(mcrBillMDTOList.get(0).getCstId());
        page.setCondition(condition);

        BaseLogUtils.newLogger("亿联线下还款，查询客户可用资金列表页面数据.DATA:").setKeys("queryCapFund", JSONObject.toJSONString(condition), CurrentThreadContext.getCurrentUserName()).info();
        Pager pager = null ;
        try {
            pager = this.capFundService.searchListPage(page);
        } catch (Exception e) {
            BaseLogUtils.newLogger("亿联线下还款，查询客户可用资金列表页面数据异常").setKeys("queryCapFund", CurrentThreadContext.getCurrentUserName()).setThrowable(e).error(LogExceptionEnum.API_CODE_0102);
        }

        Map<String, List<CapFundVO>> data = new HashMap<>();
        data.put("rows", (List<CapFundVO>)pager.getResultList());
        return data;
    }

}
